#!/bin/bash#你值得收藏的四則運算式運算。 val1=1val2=1val3=1val4=1val5=1val6=1val7=1let val1++((val2++))val3=$(($val3+1))val4=`expr $val4 + 1 `val5=`bc<<<$val5+1`val6=`echo "$val6+1"|bc`val7=$[ $val7+1 ]echo 'val1=' $val1echo 'val2=' $val2echo 'val3=' $val3echo 'val4=' $val4echo 'val5=' $val5echo 'val6=' $val6echo 'val7=' $val7
你應該瞭解的條件控制語句。
#!/bin/bash#val=1if test $val -eq 1;thenecho "hello word!"fi#!/bin/bash#val=1if [ $val -eq 1 ];thenecho "hello word!"fi#!/bin/bash#val=1[ $val -eq 1 ] && {echo "hello word!"}#[]//不支援Regex,竟然是系統命令。#[[]]//支援Regex,卻不是系統命令。#!/bin/bashval=1[[ $val -eq 1 ]] && {echo "hello word!"}
#!/bin/bash#輸入一個使用者判斷該使用者是否存在。#read -p "please input your user:" USER#a=`cut -d ":" -f1 /etc/passwd| grep "$USER"`while truedo if [ "$USER" == "$a" ];then echo "yes!this user is exit!!!" break else echo "this user no exit!!!" read -p "please input it again:" USER a=`cut -d ":" -f1 /etc/passwd| grep "$USER"` fidone