好文摘錄:http://www.twbsd.org/cht/book/ch24.htm
#!/bin/bash //這一行是必要的
# Program: //程式目的
# Program creates three files, which named by user's input
# and date command.
# History:
# 日期
# 1. 讓使用者輸入檔案名稱,並取得 fileuser 這個變數;
echo -e "I will use 'touch' command to create 3 files." # 純粹顯示資訊
read -p "Please input your filename: " fileuser # 提示使用者輸入
# 2. 為了避免使用者隨意按 Enter ,利用變數功能分析檔名是否有設定?
filename=${fileuser:-"filename"} # 開始判斷有否設定檔名,設定預設值
# 3. 開始利用 date 指令來取得所需要的檔名了;
date1=$(date --date='2 days ago' +%Y%m%d) # 前兩天的日期
date2=$(date --date='1 days ago' +%Y%m%d) # 前一天的日期
date3=$(date +%Y%m%d) # 今天的日期
file1=${filename}${date1} # 底下三行在設定檔名
file2=${filename}${date2}
file3=${filename}${date3}
# 4. 將檔名建立吧!
touch "$file1" # 底下三行在建立檔案
touch "$file2"
touch "$file3"
流程控制 - IF
echo ------------------------
s=1
e=9
v=10
if [ $v -lt $s ];then
echo " $v is smaller then $s"
elif [ $v -ge $s ] && [ $v -le $e ];then
echo " $v is between $s and $e. "
else
echo "$v is bigger then $e."
fi
沒有留言:
張貼留言