@blackwang
2016-03-28T01:54:37.000000Z
字数 960
阅读 1195
if case Shell
大于:-gt,小于:-lt,等于:-eq;
不等于:-ne,大于等于:-ge,小于等于:-le
判断条件的方括号两边必须有空格
if [command]thencommandfi
if [command]thencommandelsecommandfi
if [command1]thencommandelif [command2]thencommandfi
if [ -f 1.md ];then echo "ok";fi。目录-d、链接-l、块设备-b都是可以的。
#!/bin/bashread -p "Please input a number :" nm=`echo $n|sed 's/[0-9]//g'`if [ -n "$m"]thenecho "What you input is not a number,please try again."elseecho $nfi
#!/bin/bashread -p "Please input a number :" nm=`echo $n|sed 's/[0-9]//g'`if [ -z "$m" ]thenecho $nelseecho "你输入的不是一个数字,请重新输入"fi
grep -p 'wjy:' /etc/passwdif [ -f 1.md ] && [ -d /home ];then echo "ok";fiif [ -f 1.md -a -d /home ];then echo "ok";fi,或if [ -f 1.md -o -d /home ];then echo "ok";fi
case "$1" invalue)command1;;value)command2;;value)command3;;...Esac