為了找一個等待秒數 過了就load 預設值 的shell寫法~
紀錄
#!/bin/bash
echo -n “Enter your name > ”
read name
echo “Hi! $name”
上面的 shell script 會接收使用者的輸入. 然後在印出 Hi! 使用者.
如果要寫個 script 等待 10 秒鐘. 使用者沒回應就取消可以改寫下列程式 :
#!/bin/bash
echo -n “Please input within 10 seconds > ”
if read -t 10 input; then
echo “You just input : $input!”
else
echo “You did not input anything”
fi
Comments