當前位置:首頁 » 操作系統 » linux多個if

linux多個if

發布時間: 2023-05-16 13:17:56

Ⅰ 關於linux if多個判斷問題

1 = 1 -a 2 = 2 -a $i = 2
表達式中,=也要和數值空格分開,不然會把 1=1這種當成一個字元串處理

Ⅱ UNIX/Linux shell腳本 if語句的幾個案例

if
[條件測試1]
&&
(||)
[條件測試2];
//以if為起始,後面可以接若
then
//干個判斷式,使用&&或||
第一段程序執行內容
elif
[條件測試3]
&&
(||)
[條件測試4];
//第二段的判斷,如果第一
then
//段沒有符合就來此搜尋條件
第二段程序執行內容
else
//當前兩段都不符合時,就以這段內容來執行。
第三段程序執行內容
fi
//結束if
then的條件判斷
-------------------------------------------------------------------------------------------------
#!/bin/sh
echo
-n
「Please
input
the
answer;」
//-n不換行
read
Input
if
[
$Input
=
y
]
then
echo
"The
answer
is
right"
elif
[
$Input
=
n
]
then
echo
"The
answer
is
wrong"
else
echo
"Bad
Input"
fi
#
end

Ⅲ linux的shell腳本if判斷有哪些參數

linux 里有很多文檔可以幫助學習!

比如

GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu)
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.

A star (*) next to a name means that the command is disabled.

JOB_SPEC [&] (( expression ))
. filename [arguments] :
[ arg... ] [[ expression ]]
alias [-p] [name[=value] ... ] bg [job_spec ...]
bind [-lpvsPVS] [-m keymap] [-f fi break [n]
builtin [shell-builtin [arg ...]] caller [EXPR]
case WORD in [PATTERN [| PATTERN]. cd [-L|-P] [dir]
command [-pVv] command [arg ...] compgen [-abcdefgjksuv] [-o option
complete [-abcdefgjksuv] [-pr] [-o continue [n]
declare [-afFirtx] [-p] [name[=val dirs [-clpv] [+N] [-N]
disown [-h] [-ar] [jobspec ...] echo [-neE] [arg ...]
enable [-pnds] [-a] [-f filename] eval [arg ...]
exec [-cl] [-a name] file [redirec exit [n]
export [-nf] [name[=value] ...] or false
fc [-e ename] [-nlr] [first] [last fg [job_spec]
for NAME [in WORDS ... ;] do COMMA for (( exp1; exp2; exp3 )); do COM
function NAME { COMMANDS ; } or NA getopts optstring name [arg]
hash [-lr] [-p pathname] [-dt] [na help [-s] [pattern ...]
history [-c] [-d offset] [n] or hi if COMMANDS; then COMMANDS; [ elif
jobs [-lnprs] [jobspec ...] or job kill [-s sigspec | -n signum | -si
let arg [arg ...] local name[=value] ...
logout popd [+N | -N] [-n]
printf [-v var] format [arguments] pushd [dir | +N | -N] [-n]
pwd [-LP] read [-ers] [-u fd] [-t timeout] [
readonly [-af] [name[=value] ...] return [n]
select NAME [in WORDS ... ;] do CO set [--abefhkmnptuvxBCHP] [-o opti
shift [n] shopt [-pqsu] [-o long-option] opt
source filename [arguments] suspend [-f]
test [expr] time [-p] PIPELINE
times trap [-lp] [arg signal_spec ...]
true type [-afptP] name [name ...]
typeset [-afFirtx] [-p] name[=valu ulimit [-SHacdfilmnpqstuvx] [limit
umask [-p] [-S] [mode] unalias [-a] name [name ...]
unset [-f] [-v] [name ...] until COMMANDS; do COMMANDS; done
variables - Some variable names an wait [n]
while COMMANDS; do COMMANDS; done { COMMANDS ; }

good luck

Ⅳ 求linux shell 中if的寫法

主要是格式問題:
if [[ $jg == false ]]; then
echo -e "\033[41;37m $sj $jg \033[5;m"
elif [[ $jg != false ]]; then
echo -e "\033[42;37m $sj $jg \033[1;m"
fi
注意中間的空格,假如是字元串匹配,最好加上引號。

Ⅳ linux 每個if都要搭配一個fi嗎

每個if語句都要用fi結束,而且是每一個if都要對應一個fi。

整個if語句用fi閉合起來才算完整,書寫時if和fi要垂直對齊以方便查看。

格式舉例:

if condition

then

command1

command2

fi

condition是判斷條件,如果 condition 成立(返回「真」),那麼 then 後邊的語句將會被執行;如果 condition 不成立(返回「假」),那麼不會執行任何語句。最後必須以fi來閉合,fi 就是 if 倒過來拼寫,即使有多條語句也不需要用{ }包圍起來。


(5)linux多個if擴展閱讀

shell if多條件的格式用法介紹

shell 支持任意數目的分支,當分支比較多時,可以使用 if elif else 結構,它的格式為:

if condition1

then

statement1

elif condition2

then

statement2

elif condition3

then

statement3

else

statementn

fi

注意,if 和 elif 後邊都得跟著 then。整條語句的執行邏輯為:

如果 condition1 成立,那麼就執行 if 後邊的 statement1;如果 condition1 不成立,那麼繼續執行 elif,判斷 condition2。

如果 condition2 成立,那麼就執行 statement2;如果 condition2 不成立,那麼繼續執行後邊的 elif,判斷 condition3。

如果 condition3 成立,那麼就執行 statement3;如果 condition3 不成立,那麼繼續執行後邊的 elif。

如果所有的 if 和 elif 判斷都不成立,就進入最後的 else,執行 statementn。

熱點內容
oracle資料庫實例 發布:2025-09-16 20:23:04 瀏覽:556
java實習心得體會 發布:2025-09-16 20:06:46 瀏覽:587
outlook2010郵件加密 發布:2025-09-16 19:56:00 瀏覽:423
安卓開發公司哪個好 發布:2025-09-16 19:44:55 瀏覽:545
java編譯項目 發布:2025-09-16 19:39:15 瀏覽:559
python爬蟲數據分析 發布:2025-09-16 19:04:15 瀏覽:540
安卓錄屏大師怎麼直播 發布:2025-09-16 18:51:52 瀏覽:935
電腦怎麼解壓文件步驟 發布:2025-09-16 18:32:10 瀏覽:397
編譯器默認構造函數內聯 發布:2025-09-16 18:30:40 瀏覽:267
密碼忘了怎麼改 發布:2025-09-16 18:29:54 瀏覽:167