#!/bin/bash#你值得收藏的四则表达式运算。
val1=1 val2=1 val3=1 val4=1 val5=1 val6=1 val7=1 let val1++ ((val2++)) val3=$(($val3+1)) val4=`expr $val4 + 1 ` val5=`bc<<<$val5+1` val6=`echo "$val6+1"|bc` val7=$[ $val7+1 ] echo 'val1=' $val1 echo 'val2=' $val2 echo 'val3=' $val3 echo 'val4=' $val4 echo 'val5=' $val5 echo 'val6=' $val6 echo '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!"}#[]//不支持正則表達式。居然是系统命令。
#[[]]//支持正則表達式。却不是系统命令。 #!/bin/bash val=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