linux bash學習(一)
阿新 • • 發佈:2017-07-29
技術 bsp style code ram number mage 文件 創建
1.請你以 read 指令的用途,撰寫一個 script ,他可以讓使用者輸入:1. first name 與 2. last name, 最後並且在屏幕上顯示:“Your full name is: ”的內容:
#!/bin/bash #Program: # use input his first name and last name.Program shows his full name. #History: #2017/07/27 lzyer release read -p "Please input your first name:" firstname read -p "Please input your last name:" lastname echo "Your full name is : ${firstname}.${lastname}"
2.隨日期變化:利用 date 進行文件的創建
#!/bin/bash #Program: # Program creates three files, which named by user‘s input and date command. #History #2017/07/28 lzyer First release echo "I will use ‘touch‘ command to create 3 file." read -p "Please input your filename :" fileuser filename=${fileuser:-"filename"} 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} touch "${file1}" "${file2}" "${file3}"
3.數值運算:簡單的加減乘除
#!/bin/bash #Program: # use input 2 integer numbers; program will cross these two numbers. #History: #2017/07/28 lzyer First release echo "you should input 2 numbers, i will multipfying them !" read -p "first numbe: " firstnumber read -p "second number: " secondnumber total=$((${firstnumber}*${secondnumber})) echo "The result of ${firstnumber} x ${secondnumber} ==> ${total}"
4.sh和source的差異性
linux bash學習(一)