test 字符串比较命令:
-n str1 str1 is not null (has length greater than 0) 不为空并且长度大于0
-z str1 str1 is null (has length 0) 为空或者长度为0
更细致的文档推荐在字符串比较时尽量不要使用 -n ,而用 ! -z 来代替。(其中符号 "!" 表示求反操作)
//对于字符串的比较,最好使用[[]]运算符
#!/bin/bash
if [[ "abc" < "cde" ]]; then
echo 'ok'
fi
-------------------------------------------------------------------------------------------
AIC2 ftp1204/.dd> cat case.sh
#!/bin/bash
i="li da"
###将所有的变量用“”是一个好习惯“,如下面的这种情况就必须使用“”,否则error
case "$i" in
li da) //应该写为:"li da")
echo 'ok'
;;
*)
echo 'no ok'
esac
//例子
#!/bin/bash
read -p "input your choose:" i
case $i in
1 | 2) ###########注意这里的用法################
echo 'ok'
;;
*)
echo 'other'
;;
esac
-------------------------------------------------------------------------------------------
echo "this is the $numnd"
上述脚本并不会输出"this is the 2nd",只会打印"this is the ";
这是由于shell会去搜索变量numnd的值,而实际上这个变量此时并没有值。
可以使用花括号来告诉shell我们要打印的是num变量:
代码:
num=2
echo "this is the ${num}nd"
---------------------------------------------------------------------------------
find . -type f | xargs rm -rf ;
find . -type d -ok file {} \; //这种方式会每次都进行询问
任何形式的命令都可以在-exec选项中使用
find . -name "*.log" -exec rm -rf {} \;
ftp1204@AIC2:~/.dd/backdir> find . -name "dos.txt" -exec ls {} \;
./dos.txt
ftp1204@AIC2:~/.dd/backdir> find . -name "dos.txt" | xargs ls
./dos.txt
---------------------------------------------------------------------------------
打/解包到指定的目录:使用 tar 的 -C 选项,如 tar xvf newarc.tar.gz -C tmp/a/b/c。
-------------------------------------------------------------------------------------------
#删掉七天前的日志
find $IDEA_LOG_DIR -mtime +7 -exec rm -rf {} \;
tmp=`cat $fileLocation| sed -e "s/192.168.163.41/$madm_srv/g" \
|sed -e "s/192.168.163.40/$aemc_srv/g" \
|sed -e "s/bond0/$netcard/g" \
|sed -e "s/255.255.255.240/$NetMask/g" \
|sed -e "s/192.168.163.47/$BroadCast/g" \
|sed -e "s/mad1/$MainHost/g" \
|sed -e "s/mad2/$SlaveHost/g" \
|sed -e "s/madcluster/$ClusterName/g" \
修改权限时才用-R,其他的都是小写的r
chmod -R 777 /sharedisks/