分页: 1 / 1

一个图床的脚本

发表于 : 2013-06-10 15:18
ceclinux
写了一个图床和贴代码的脚本,当变量是代码文件的时候上传到代码的pastebin,当变量是图片的时候上传到图床

图片

代码: 全选

#Toggle the  values  of variables controlling optional shell behavior.
#use nocasematch must use [[]]?
shopt -s nocasematch
if [[ "$1" == /* ]]
then
   currpath="$1"
else
	currpath="$(pwd)/$1"
fi
for i in $(echo "$1"|sed 's/[^.]*.\([a-zA-Z]*\)/\1/g')
do
	if [[ "$i" == "jpg" ]] || [[ "$i" == "png" ]] || [[ "$i" == "gif" ]] || [[ "$i" == "jpeg" ]] || [[ "$i" == "svg" ]]
	then
		curl -F "name=@$currpath" http://img.vim-cn.com/
	else
		cat $currpath| curl -F "vimcn=<-" http://p.vim-cn.com
	fi
done 
想不通,当我使用
shopt -s nocasematch
if语句
if [[ "$i" == "jpg" ]] || [[ "$i" == "png" ]] || [[ "$i" == "gif" ]] || [[ "$i" == "jpeg" ]] || [[ "$i" == "svg" ]]
是可以匹配到大写和小写的,也就是说,PNG和png都可以匹配
如果吧上面的If语句中两个[[都改成一个[,就不能匹配大写了
bash语法有点乱,求点播 :em20

Re: 一个图床的脚本

发表于 : 2013-06-19 17:03
bzhao
man bash:
nocasematch
If set, bash matches patterns in a case-insensitive fashion when performing matching
while executing case or [[ conditional commands.

nocasematch 是说对string pattern有作用的, [] 里面只能是字符串本身。