-t选项指定了read命令等待输入的秒数。当计时器过期后,read命令会返回一个非零退出状态码。 #!/bin/bash # timing the data entry # if read -t 5 -p "Please enter your name: " name then echo "Hello $name, welcome to my script" else echo echo "Sorry, too slow! " fi 示例 如果计时器过...
read -s -p "Please enter your password:" passwd [ "$passwd" == "123456" ]&&echo "password is right!"&&exit 0 [ "$passwd" != "123456" ]&&echo "password is not right,Please input again!"&&continue done 执行: 1 2 3 4 5 yuanqiangfei@ubuntu:~/script$ ./read.sh Please en...
read -n1 -p "Do you want to continue [Y/N]:" case $REPLY in Y | y ) echo echo "fine,continue";; N | n ) echo echo "ok, bye";; esac echo "END of the script" image.png 14.6.3 隐藏方式读取 使用read -s命令可以避免输入的内容出现在显示器上,最典型的例子就是输入密码,如下图...
Y Fine,continue on... This is the end of the script 上述例子中,-n选项与值1一起使用,它告诉read命令在接收单个字符后退出。只要按下单个字符后,read命令就会接收输入并将它传给变量,无需按下回车键。 6.3 隐藏方式读取 有时候需要从用户输入处得到输入,但又不能在屏幕中显示输入。其中典型的例子就是输入...
# Besides, this script will create a ".hostlist" local file to temp the hosts, so if you want to move the script, remembermove the temp file too. # Last Modify: # 2014-7-2 # Useage : # $ /bin/bash easy_ssh.sh (chmod +x easy_ssh.sh ; ./easy_ssh.sh) ...
# Information: Set password for script # Create Date: 2011-02-12 # Version: v1.0 ### stty -echo echo -n "Please input your password: " read pass1 echo "" echo -n "Please input your password again: " read pass2 echo "" stty echo...
2. if read -t 5 -p "please enter your name:" name 3. then 4. echo "hello $name ,welcome to my script" 5. else 6. echo "sorry,too slow" 7. fi 8. exit 0 1. 2. 3. 4. 5. 6. 7. 8. 除了输入时间计时,还可以设置read命令计数输入的字符。当输入的字符数目达到预定数目时,自动...
read-d":"var 示例 以下是read命令的示例: 读取输入并赋值给变量1987name: 代码语言:javascript 复制 # read 1987name #等待读取输入,直到按回车表示输入完毕,并将输入赋值给变量answer HelloWorld #控制台输入Hello #echo $1987name #打印变量 HelloWorld ...
./script param1 param2 b) 通过 read 命令 read-p"Destination backup Server : "desthost 70) 在脚本中如何使用 "expect" ? /usr/bin/expect<<EODspawnrsync-ar${line}${desthost}:${destpath}expect"*?assword:*"send"${password}\r"expecteofEOD ...
read命令是bash内置命令,用来从标准输入中读取数据。比如可以交互式读取用户在终端的输入,读取管道数据,读取标准输入重定向数据,等等。 读取文件中数据的方式: 按字符数读取 按分隔符读取 按行读取 一次性读完所有数据 按字节数读取(read命令不支持) 语法: ...