if [ expression ] then Statement(s) to be executed if expression is true fi
if ... fi 语句 if ... else ... fi 语句 if ... elif ... else ... fi 语句
#!/bin/bash/ a=10 b=20 if [ $a == $b ] then echo "a is equal to b" elif [ $a -gt $b ] then echo "a is greater to b" else echo "a is less to b" fi
a=10;b=20;if [ $a == $b ];then echo "a is equal to b";else echo "a is not equal to b";fi;
#!/bin/bash/ a=10 b=20 if test $a == $b then echo "a is equal to b" else echo "a is not equal to b" fi
#!/bin/bash/ grade="B" case $grade in "A") echo "Very Good!";; "B") echo "Good!";; "C") echo "Come On!";; *) echo "You Must Try!" echo "Sorry!";; esac
#include <stdio.h>
int main(){
char grade = 'B';
switch(grade){
case 'A': printf("Very Good!");break;
case 'B': printf("Very Good!");break;
case 'C': printf("Very Good!");break;
default:
printf("You Must Try!");
printf("Sorry!");
break;
}
return 0;
}
#!/bin/bash
option="${1}"
case ${option} in
"-f") FILE="${2}"
echo "File name is $FILE"
;;
"-d") DIR="${2}"
echo "Dir name is $DIR"
;;
*)
echo "`basename ${0}`:usage: [-f file] | [-d directory]"
exit 1 # Command to come out of the program with status 1
;;
esac
$./test.sh test.sh: usage: [ -f filename ] | [ -d directory ] ./test.sh -f index.html File name is index.html
do command1 command2 ... commandN done
#!/bin/bash/ for value in 1 2 3 4 5 do echo "The value is $value" done
The value is 1 The value is 2 The value is 3 The value is 4 The value is 5
for str in 'This is a string' do echo $str done
#!/bin/bash for FILE in * do echo $FILE done
beijing tianjin shanghai #!/bin/bash citys=`cat city.txt` for city in $citys echo $city done
#!/bin/bash c=0; while [ $c -lt 3 ] do echo "Value c is $c" c=`expr $c + 1` done
#!/bin/bash c=0; until [ $c -eq 3 ] do echo "Value c is $c" c=`expr $c + 1` done
#!/bin/bash i=0 while [ $i -lt 5 ] do i=`expr $i + 1` if [ $i == 3 ] then break fi echo -e $i done
#!/bin/bash i=0 while [ $i -lt 5 ] do i=`expr $i + 1` if [ $i == 3 ] then continue fi echo -e $i done
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有