2023年8月2日发(作者:)
shell脚本——判断语句if的基本语法if [ command ];then 符合该条件执⾏的语句elif [ command ];then 符合该条件执⾏的语句else 符合该条件执⾏的语句fiif的特殊⽤法[ commend ] ⾥⾯的命令⼀定都需要空格分割开(1)针对⽂件if [ -f file ] 如果⽂件存在if [ -e file ] 如果⽂件存在if [ -d … ] 如果⽬录存在if [ -s file ] 如果⽂件存在且⾮空if [ -r file ] 如果⽂件存在且可读if [ -w file ] 如果⽂件存在且可写if [ -x file ] 如果⽂件存在且可执⾏(2)针对整数if [ int1 -eq int2 ] 如果int1等于int2if [ int1 -ne int2 ] 如果不等于if [ int1 -ge int2 ] 如果>=if [ int1 -gt int2 ] 如果>if [ int1 -le int2 ] 如果<=if [ int1 -lt int2 ] 如果<(3)针对字符串If [ $a = $b ] 如果string1等于string2,字符串允许使⽤赋值号做等号if [$string1 != $string2 ] 如果string1不等于string2if [ -n $string ] 如果string ⾮空(⾮0),返回0(true)if [ -z $string ] 如果string 为空if [ $sting ] 如果string ⾮空,返回0 (和-n类似)多条件判断&&、||&&:表⽰前⼀条命令执⾏成功,才执⾏后⼀条命令||:表⽰上⼀条命令执⾏失败后,才执⾏下⼀条命令
发布者:admin,转转请注明出处:http://www.yc00.com/web/1690919147a463474.html
评论列表(0条)