请问大侠,这个SHELL的${}里面的-"filename"是啥意思啊?
发表于 : 2011-01-12 16:26
# 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"
其他都明白,就是这句
filename=${fileuser:-"filename"} # 開始判斷有否設定檔名
他说判断,是如何判断的?我的认识中,${}表示括起来的是一个变数,上面这句就是说${fileuser},但是加了:-"filename"就不知道什么意思了,那个-什么意思?那个:什么意思?我知道-可以表示standin,:可以表示间隔
谢谢
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"
其他都明白,就是这句
filename=${fileuser:-"filename"} # 開始判斷有否設定檔名
他说判断,是如何判断的?我的认识中,${}表示括起来的是一个变数,上面这句就是说${fileuser},但是加了:-"filename"就不知道什么意思了,那个-什么意思?那个:什么意思?我知道-可以表示standin,:可以表示间隔
谢谢