bash脚本一些语句的语法
if:
if [ $num1 -eq $num2 ];then echo true else echo false fi
(-eq =, -lt <, -gt >, -a and, -o or)
if [ $str1 = $str2 ];then echo ture else echo false fi
for:
for i in 1 2 3 4 5 do echo $i done
for i in `seq 1 100` do echo $i done
for((i=1;num<=100;num++)) do echo $num done
while:
while((i<=10)) do echo $i ((i++)) done
until:
until [ ! $i -lt 10 ] do echo $i ((i++)) done
case:
case $num in 1)echo num is 1 ;; 2)echo num is 2 ;; *)echo num is other ;; esac
函数:
func(){ echo "$1 $2" } func hello world
脚本调用:
. 1.sh
source 1.sh