fnpd.net
当前位置:首页 >> shEll iF EliF >>

shEll iF EliF

awk ' { if ($1==1) print "A" else if ($1==2) print "B" else print "C" }' #命名为1.sh 执行方法:echo "1" | sh 1.sh 写成一行: echo "3" | awk '{if ($1==1) print "A"; else if ($1==2) print "B"; else print "C"}'

1) bash a=3 ; b=2 ; c=4 if (( a > b )) && (( a < c )) 或者 if [[ $a > $b ]] && [[ $a < $c ]] 或者 if [ $a -gt $b -a $a -lt $c ] 2) a=3 ; b=2 ; c=4 if (( a > b )) || (( a < c )) 或者 if [[ $a > $b ]] || [[ $a < $c ]] 或者 if [ $...

if test $# -eq 0 如果脚本参数的个数是0 then echo `You must give a filename` 显示 你必须给一个文件名 elif test ! -s $1 否则,如果脚本参数的文件大小为0 then echo `no file $1` 显示,所给的参数不是一个文件 else cat $1 否则,显示文...

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

echo "你继续吗?Y or N" read ANSWER if [ “$ANSWER” = “Y” -o “$ANSWER” = “y” ] ; then echo "你选择了$ANSWER"; elif [ “$ANSWER” = “N” -o “$ANSWER” = “n” ] ; then echo "你选择了$ANSWER"; else echo "输入错误" exit fi -----你试试

简单的写了个,不考虑异常输入 #!/bin/bash if [ $1 -gt 100 ] then echo "the number is greater than 100" elif [ $1 -lt 10 ] then echo "the number is smaller than 10" else echo "the number is between 10 and 100"

echo "你继续吗?Y or N" read ANSWER if [ “$ANSWER” = “Y” -o “$ANSWER” = “y” ] ; then echo "你选择了$ANSWER"; elif [ “$ANSWER” = “N” -o “$ANSWER” = “n” ] ; then echo "你选择了$ANSWER"; else echo "输入错误" exit fi 这部分我是看的...

c的写法: a = 10; if (b >= a+2) c = 0; else c = 1; shell的写法: num1=$[2*3] num2=$[1+5] if test $[num1] -eq $[num2] then echo 'The two numbers are equal!' else echo 'The two numbers are not equal!' fi

shell脚本中的or和C语言类似,也是用||(两个竖杠)表示or逻辑。但是在shell脚本中,有严格的执行顺序要求,前一条命令或语句返回false,||的下一条语句或命令才会执行。

-f file文件存在为真 例子: if [ -f "\a.txt ] then echo "file exist" else echo " not exist" fi

网站首页 | 网站地图
All rights reserved Powered by www.fnpd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com