[root@linux scripts]# vi sh03.sh #!/bin/bash # Program: # Let user keyin their first and last name, and show their full name. # History: # 2005/08/23 csie First release read -p "Please input your first name: " firstname read -p "Please input your last name: " lastname # read -p 後面接提示字元 echo -e "\nYour full name is: $firstname $lastname" # echo -e enable interpretation of backslash escapes(解釋 \n 為 new line)
[root@linux scripts]# vi sh04.sh
#!/bin/bash
# Program:
# User can keyin filename to touch 3 new files.
# History:
# 2005/08/23 csie First release
# 1. 讓使用者輸入檔案名稱,並取得 fileuser 這個變數;
echo -e "I will use 'touch' command to create 3 files."
read -p "Please input the filename what you want: " 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
[root@linux scripts]# vi sh05.sh #!/bin/bash # Program: # User can input 2 integer to cross by! # History: # 2005/08/23 csie First release echo -e "You SHOULD input 2 number, I will cross they! \n" read -p "first number: " firstnu read -p "second number: " secnu total=$(($firstnu*$secnu)) echo -e "\nThe number $firstnu x $secnu is ==> $total"
+, -, *, /, % 等。其中 % 是取餘數 13 對 3 取餘數,例如:
[root@linux scripts]# nu=$((13%3)); echo $nu 1
echo -e "\nvar= " var
+%Y%m%d`
$(($nu1*$nu2))
$(($nu1/$nu2))
$(($nu1%$nu2))
2017-06-14