Shell指令碼迴圈讀取文字、獲取時間格式時間、函式傳參.md
阿新 • • 發佈:2021-01-07
迴圈讀取文字
filepath = "/root/temp/啟動程序.txt"
echo $filepath
while read line
do
echo $line
done < $filepath
filepath="/root/temp/啟動程序.txt"
echo $filepath
while read line
do
echo $line
done < $filepath
注意到:filepath=
"/root/temp/啟動程序.txt"空格的緣故:linux shell中自動變數名和=間
不可有空格
其中while do … … done < filepath是將檔案重定向給while迴圈進行操作
獲取指定時間格式時間
date_alarm=`date +"%Y%m%d%H%M"`
輸出標準時間格式,注意date和“+”號之間要有空格
。
傳參和函式
function sayHello
{
first_word=$1
second_word=$2
third_word=$3
echo "第一個引數: $first_word 第二個引數: $second_word 第三個引數: $third_word"
}
sayHello first second third
可以注意到直接採用$
加數字
的方法直接在呼叫函式後面對應指定的引數即可。