shell語言 循環語句怎么寫
echo –n “input:”
read user
if 多條指令,這些命令之間相當于“and”(與)
grep $user /etc/passwd >/tmp/null
who -u | grep $user then 上邊的指令都執行成功,返回值$?為0,0為真,運行then
echo "$user has logged"
else 指令執行失敗,$?為1,運行else
echo "$user has not logged"
fi
linux shell的if語句
echo "你繼續嗎?Y or N"
read ANSWER
if [ “$ANSWER” = “Y” -o “$ANSWER” = “y” ] ; then
echo "你選擇了$ANSWER";
elif [ “$ANSWER” = “N” -o “$ANSWER” = “n” ] ; then
echo "你選擇了$ANSWER";
else
echo "輸入錯誤"
exit
fi
-----你試試
shell腳本中的if中多條件語句如何寫
寫法:if [ $a = "aa" -a $b = "bb" ] || [$c = "cc" -a $d = "dd" ];
then
echo "success"
fi
擴展資料:
shell腳本if判斷多個條件
1、如果a>b且aif (( a >b )) && (( a $b ]] && [[ $a 2、如果a>b或aif (( a >b )) || (( a $b ]] || [[ $a 3、 -o = or , -a = and , 但我一向只用 || 或者 &&
4、-ne 比較數字 (numberic) ; != 比較字符 (string), 但后者拿來比較數字也可,只是不是標準用法 -lt 是等同 -lt , -eq , -gt , -ge -le , 這些是 test , 就是 [ ] 這個內建命令使用的條件操 作符, 數字用, = , != 字符用, == 這個該是 [[ ]] 用的, 可用來比對正規表示式, 但用在 [ ] 也可。
shell 編程 里面 if 嵌套 for 語句的匪夷所思的 事情
#!/bin/bash
RATEMIN1=40
RATEMIN5=60
echo $RATEMIN1 -le 50
echo $RATEMIN5 -ge 50
if [ $RATEMIN1 -le 50 ] && [ $RATEMIN5 -ge 50 ]
then
for i in 1 2 3 4 5
do
eval value='$'RATEMIN$i
if [ ! -n "$value" ];then
continue
fi
if [ $value -ge 50 ]
then
echo "FUCK!"
break
fi
continue
done
fi
求大神解答 shell腳本中的循環語句 謝謝
假如你的txt中,每一行有一個名字,假設文件名是*
i=0
while read line
if [ $i -eq 10 ]
then
break
fi
//處理內容,每一行中獲取的內容,也就是名字已經賦值在line當中,可以直接通過他使用
//例子
if [ "$line" = "example" ]
then
echo "Hello example"
break
else
(( i++ ))
fi
done
shell中的for語句疑惑
以下是man里的說明,有說到如果 for in 的 in 語句省略的話,就對位置參數進行循環。所以你的理解是對的:
for name [ [ in [ word 。 ] ] ; ] do list ; done
The list of words following in is expanded, generating a list of items. The variable name is set to
each element of this list in turn, and list is executed each time. If the in word is omitted, the for
command executes list once for each positional parameter that is set (see PARAMETERS below). The return
status is the exit status of the last command that executes. If the expansion of the items following in
results in an empty list, no commands are executed, and the return status is
輸出五個菜單,包括一個退出菜單,用到if for while case循環結構的
這個程序可以用Visual Basic的循環結構來做。
循環結構允許重復執行一行或幾行代碼。Visual Basic支持的循環結構有Do…Loop、For…Next、For Each…Next。
用Do循環重復執行一個語句塊,且重復次數不定。Do…Loop有幾種形式以計算數值為條件以決定是否繼續執行。條件必須是一個數值或者值為True或False的表達式。
在下面的Do…Loop循環中,只要條件為真就執行循環。
Do While 循環條件
循環語句塊
Loop
當Visual Basic執行到這個Do循環時首先測試條件,條件為假時,跳過所有語句。如果條件為真,Visual Basic就會執行語句,退回到Do While語句測試條件。只要條件為真,循環可以隨意執行幾次。如果條件一開始便為假,則不會執行語句。
;還有一種Do…Loop語句,是先執行語句,每次執行之后測試條件,循環中的語句至少執行一次。
Do
循環語句塊
Loop While 循環條件
希望我能幫助你解疑釋惑。
轉載請注明出處華閱文章網 » shelliffor循環語句