一个图床的脚本

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
ceclinux
帖子: 308
注册时间: 2013-01-17 2:42
系统: Ubuntu 12.04LTS

一个图床的脚本

#1

帖子 ceclinux » 2013-06-10 15:18

写了一个图床和贴代码的脚本,当变量是代码文件的时候上传到代码的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
Ubuntu 12.04 LTS
laptop:Acer 4750G CPU:I5-2410
内存:2+2G 硬盘:500+750
http://www.ceclinux.org
头像
bzhao
帖子: 254
注册时间: 2008-07-05 2:15
系统: XUbuntu

Re: 一个图床的脚本

#2

帖子 bzhao » 2013-06-19 17:03

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有作用的, [] 里面只能是字符串本身。
Bill Z
stat -c %a filename
\_.\{-}
回复