Shell指令碼[運算運算式,條件控制語句]

來源:互聯網
上載者:User
#!/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
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.