#!/bin/bash# -t选项:指定一个计时器,指定read命令等待输入的秒数。# 如果计时器超时,read命令会返回非0退出状态码。# using the read mmommand with a timerifread-t5-p"Ener your name: " name
thenecho"hello $name, welcome to my script."elseechoecho"sorry, no longer waiting for name."fi
运行结果
Ener your name:
sorry, no longer waiting for name.
Ener your name: liergou
hello liergou, welcome to my script.
-n 选项
echo"-n选项: -n 1——告诉read命令在接收到单个字符后退出。"read-n1-p"Do you want to continue [Y/N]/?" answer
case$answerin
Y | y)echoecho"okay. continue on ...";;
N | n)echoecho"okay. goodby";;esacecho"this is the end of the script."
运行结果
-n选项: -n1——告诉read命令在接收到单个字符后退出。
Do you want to continue[Y/N]/?y
okay. continue on ...
this is the end of the script.
-n选项: -n1——告诉read命令在接收到单个字符后退出。
Do you want to continue[Y/N]/?athis is the end of the script.