shell程式設計筆記

2021-07-17 04:41:41 字數 802 閱讀 1427

第一天學習shell程式設計,自己做的筆記;

test1:

#!/bin/sh

#judge dir exist

if [ ! -d /data/20140515 ];then

mkdir -p /data/20140515

else

echo 「this dir is exist,please exit …..」 fi

#!/bin/sh

scores=80;

if [[ $scores -gt 85 ]]; then

echo "very good!";

elif [[ $scores -gt 75 ]]; then

echo "good!";

elif [[ $scores -gt 60 ]]; then

echo "pass!";

else

echo "no pass!";

fi;邏輯運算子解析:

-f 判斷檔案是否存在 eg: if [ -f filename ]

-d 判斷目錄是否存在 eg: if [ -d dir ]

-eq  等於 應用於:整型比較

-ne  不等於 應用於:整型比較

-lt 小於 應用於:整型比較

-gt  大於 應用於:整型比較

-le  小於或等於 應用於:整型比較

-ge  大於或等於 應用於:整型比較

-a 雙方都成立(and) 邏輯表示式 –a 邏輯表示式

-o 單方成立(or) 邏輯表示式 –o 邏輯表示式

-z 空字串

shell程式設計筆記

if 1 eq 1 a 2 2 then echo true elif 1 lt 2 o 3 gt 4 then echo else echo false fi gt lt ge le eq ne a o if f 1.sh echo 1.sh exists if e 1.sh then echo ...

Shell程式設計筆記

1,變數命名規則 your name runoob.com 注意,變數名和等號之間不能有空格,這可能和你熟悉的所有程式語言都不一樣。同時,變數名的命名須遵循如下規則 命名只能使用英文本母,數字和下劃線,首個字元不能以數字開頭。中間不能有空格,可以使用下劃線 不能使用標點符號。不能使用bash裡的關鍵...

shell 程式設計筆記

告訴系統用什麼指令碼進行編輯 常用 bin bash。在對變數進行賦值時,規避空格符。單雙引號的使用,單引號成對出現,且在單引號中不能使用變數,但可以在雙引號中使用單引號加變數的形式。例如 bin bash var jj help var xx var jj var ll var jj me ech...