www.ntzj.net > shEll脚本中的iF中多条件语句如何写.

shEll脚本中的iF中多条件语句如何写.

if [ $a = "aa" -a $b = "bb" ] || [$c = "cc" -a $d = "dd" ]; then echo "success" fi 是这个意思吗

可以用case #!/bin/sh case a1 in 111) ttt ;; 222) ttt ;; *) bbb ;; esac

else和if之间要有个空格

if [ expression 1 ] then Statement(s) to be executed if expression 1 is true elif [ expression 2 ] then Statement(s) to be executed if expression 2 is true elif [ expression 3 ] then Statement(s) to be executed if expression 3 ...

#其中mkdir外面的符号是esc下来那个按键上的符号,表示执行命令#!/bin/bashif [ `mkdir -p ~/1/1` -a `mkdir ~/2` ];then echo "成立{$?}"else echo "不成立{$?}"fi

[ -z "$3" ] || [[ "$3" =~ '[1-7]' ]]

-a是and,左右条件两者都成立 -o是or,左右条件任意一条成立

while ( [ "$a" = "a" ] || [ "$a" = "b" ] ) do done 注意方括号和圆括号和 等号 两边的 空格。

while read filename do done< /home/ismp/auto_dep/dep_file_name 然后sh -x yourshell 看看操作过程

sh -x ./test1.sh 你可以看到执行过程 判断稍微改下[ "x$X" == "xN" ]

网站地图

All rights reserved Powered by www.ntzj.net

copyright ©right 2010-2021。
www.ntzj.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com