- 1、本文档共42页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * test 命令的操作符 例子: $str1=abcd $str2=abcd $test $str1 $[ $str1 ] $echo $? $test $str1 = $str2 $[ $str1 = $str2 ] $echo $? 0 1 测试$str1是否非空 测试$str1与$str2是否相等 * test 命令的操作符 整数操作符 int1 –eq int2 数值相等 int1 –ne int2 数值不等 int1 –lt int2 int1 int2 int1 –gt int2 int1int2 int1 –le int2 int1= int2 int1 –ge int2 int1=int2 * test 命令的操作符 例子:整数操作符与字符串操作符 $str1=1234 $str2=01234 $[ $str1 = $str2 ] $echo $? $[ $str1 –eq $str2 ] $echo $? 1 0 字符串比较 数值大小的比较 THANK YOU SUCCESS * * 可编辑 * test 命令的操作符 文件操作符:测试文件状态 -e file 文件file存在 -d file 文件file是一个目录 -f file 文件file是一个普通文件 -s file 文件file大小不为0 -r file 可读 -w file 可写 -x file 可执行 逻辑操作符:测试多个条件的与(and)或(or)组合 -a 逻辑与 -o 逻辑或 ! 逻辑非 对文件所有者的权限 * 文件操作符 例子:假设以admin用户登录系统 $ls –l aa -rw-rw-r-- 1 admin admin 32 Apr 12 10:51 aa $ [ -w aa ] $ test -w aa $ echo $? $[?! -d aa ] $ echo $? 0 0 * 逻辑操作符 例子:假设以admin用户登录系统 $ls –l aa -rw-rw-r-- 1 admin admin 32 Apr 12 10:51 aa $[ -r aa -a -x aa ] $echo $? $[ -x aa -o -s aa ] $ echo $? $x=0 $[ $x -ge 0 –a $x -lt 10 ] $ echo $? 1 0 0 * Shell 脚本实例1 #!/bin/bash # testing string equality testuser=rich If [ $USER = $testuser ] then echo “Welcome $testuser” else echo “This isn’t $testuser” fi $ ./test * Shell 脚本实例2 #!/bin/bash # basic example of “for” for sta in Alabama Alaska Arizona California do echo The next state is $sta done $./test The next state is Alabama The next state is Alaska The next state is Arizona The next state is California * Shell 脚本实例3 #!/bin/bash # create a log file today=`date +%y%m%d` ls /usr/bin –al log.$today * Shell 脚本实例4 #!/bin/bash echo “Enter password” read trythis while [ “$trythis” != “sectret” ]; do echo “Sorry, try again”
文档评论(0)