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"}'

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

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 -----你试试

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

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

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 这部分我是看的...

可以尝试 吧if 的[ 换成 if [[ $ID -eq 1 ]]

continue这里没用, continue是跳出循环,这里没有循环 还有if需与fi配对, 不应该只有一个fi

因shell还不是很熟练,所以做此笔记,方便查看。 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x "$myPath"]; then mkdir "$myPath" fi #这里的-...

while [ $c != "1" && $c != "2" ] 改成 while [[ $c != "1" ] && [ $c != "2" ]]

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