代码: 全选
#!/bin/bash
function usage {
echo "Usage: $(basename $0) <filename>
Upload an image to xxxxx.me and output its URL to stdout.
If xsel or xclip is available, the URL is put on the X selection for easy pasting." >&2
}
if [ $# != 1 ]; then
echo "No file specified" >&2
exit 1
elif [ ! -f "$1" ]; then
echo "File \"$1\" not found" >&2
exit 1
fi
# check for curl
which curl >/dev/null 2>/dev/null || {
echo "Couln't find curl, which is required." >&2
exit 1
}
# upload the image
response=$(curl -F "uploadfile=@$1" "http://xxxxx.me/index.php?type=uploadv3&key=QT5LGz7ktGFVZpfFArVHCpEvDcC3qrUZrf0kP" 2>/dev/null)
if [ $? != 0 ]; then
echo "Upload failed" >&2
exit 2
fi
# parse the response and output our stuff
status=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f1 | cut -d: -f2)
if [ $status != 1 ]; then
echo "Some sort of error occurred" >&2
exit 1
fi
img=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f2 | cut -d: -f2)
ext=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f3 | cut -d: -f2)
file="$img.$ext"
url="http://xxxx.me/$file"
echo $url
或者给一个参考类似的 shell 脚本 ~~ 多谢