當前位置:首頁 » 編程軟體 » linuxbash腳本if

linuxbash腳本if

發布時間: 2023-08-04 03:32:04

linux的shell 腳本里怎麼用if 判斷文件大小呀

需要幾個工具 基本上思路是 用 配合awk取得文件大小 ,然後if判斷
偽代碼如下

s=` -k logfile|awk '{print $1}'`
if [ $s -gt 1024000000 ]
then
停止oracle監聽進程
rm -rf logfile && touch logfile
啟動oracle監聽進程
else
continue
fi

② 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 bash;if命令

必須指定路徑
類似的還有
if [ -f filename ] 測試是否是普通文件
if [ -z filename ] 測試文件是否為空
if [ -r filename ] 測試文件是否可讀
if [ -w filename ] 測試文件是否可寫

④ Shell腳本中的if和case邏輯判斷

在shell腳本中,if邏輯判斷的基本語法為:

例如:

需要注意的是shell的判斷語句也有特殊的格式,例如(($a<60)),必須有兩層括弧。此外還可以使用[]的形式,但是不能用>、<這些關系運算符了,使用[]的對應符號如下(注意'['的右邊和']'的左邊時必須留出空格):

Shell腳本中還經常用if來判斷文檔的屬性,具體格式為:

參數-e是判斷文件是否存在的,其他常用參數如下:

使用case的語法為:

case結構不限制value的個數,*代表所有其他值。下面是一個示例腳本,用來判斷奇數還是偶數:

參考: 跟阿銘學Linux(第2版)

⑤ linux shell 腳本中if語句的用法 在腳本中使用if if[! -w 「$logfile」 ] 為什

if[!-w"$logfile"]
thenecho"notwriteable"
echo"notwriteableagain"
fi

注意空格,shell裡面有的地方必須有空格,有的地方必須沒有空格。[ ]前後都要有空格

⑥ 在linux下shell腳本中if中用到or怎麼寫

linux下shell腳本的邏輯的or用運算符 || 表示,if中用到or的寫法實例如下:

a=10

b=20

if[[$a-lt 50||$b-gt 50]]

then

echo"返回 true"

else

echo"返回 false"

fi

其中$a-lt100表示a<50 為真;$b-gt 50 表示b>50為假;真 or 假為真。

所以輸出結果為:返回 true


(6)linuxbash腳本if擴展閱讀

1、shell中流程式控制制if基本語法介紹:

if condition

then

command1

command2 ...

commandN

fi


2、shell中的另一個邏輯運算符and (&&)用法實例介紹:

a=10

b=20

if[[$a-lt100&&$b-gt100]]

then

echo"返回 true"

else

echo"返回 false"

fi

輸出結果為:返回 false

⑦ 求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 shell腳本10 字元串相關的if判斷


字元串比較包括

注意 :這里的符號要 轉義 ,否則變成了重定向了。

運行結果:

注意 :上面的 等號左右兩側 中括弧內側 一定要有空格

運行結果:

以上的例子,說明 小寫字母排在字典的後面 (類似於ascii的大小)。


sort 可以對字元串排序,sort 命令會把小寫字母放在前面


運行結果:

注意上面的 中括弧內側 一定要有空格。

注意 :有時候想在字元串比較的時候使用 正則表達式 ,可以使用 雙方括弧 ,如:

運行如下:

注意:上面的 雙等號左右兩側,中括弧內側 一定要有空格

⑨ 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
-----你試試

熱點內容
安卓如何鑒別手機真假 發布:2025-02-05 14:28:15 瀏覽:119
ffmpeglinux編譯 發布:2025-02-05 14:28:04 瀏覽:544
伺服器如何做界面 發布:2025-02-05 14:27:23 瀏覽:290
訪問學者單位推薦意見 發布:2025-02-05 14:13:05 瀏覽:853
微信密碼鎖忘了怎麼辦 發布:2025-02-05 14:11:07 瀏覽:311
web是什麼文件夾 發布:2025-02-05 14:11:05 瀏覽:235
對信訪問題調查 發布:2025-02-05 14:09:39 瀏覽:984
singlephp 發布:2025-02-05 14:09:24 瀏覽:774
資料庫的欄位命名規則 發布:2025-02-05 13:53:16 瀏覽:684
固定ip自建伺服器訪問 發布:2025-02-05 13:53:03 瀏覽:741