首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

shell总结(9)

2012-10-27 
shell小结(9)test 字符串比较命令: -n str1str1 is not null (has length greater than 0) 不为空并且长度

shell小结(9)

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/bashif [[ "abc" < "cde" ]]; then        echo 'ok'fi-------------------------------------------------------AIC2 ftp1204/.dd> cat case.sh#!/bin/bashi="li da"###将所有的变量用“”是一个好习惯“,如下面的这种情况就必须使用“”,否则errorcase "$i" inli da) //应该写为:"li da")        echo 'ok'        ;;*)        echo 'no ok'esac//例子#!/bin/bashread -p "input your choose:"  icase $i in1 | 2)    ###########注意这里的用法################        echo 'ok'        ;;*)        echo 'other'        ;;esac-------------------------------------------------------echo "this is the $numnd"  上述脚本并不会输出"this is the 2nd",只会打印"this is the ";这是由于shell会去搜索变量numnd的值,而实际上这个变量此时并没有值。可以使用花括号来告诉shell我们要打印的是num变量:代码:num=2echo "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.txtftp1204@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,其他的都是小写的rchmod -R 777 /sharedisks/

?

热点排行