How to Prompt for User Input in Linux shell script
Written by Rahul, Updated on November 5, 2014
from here:
How to Prompt for User Input in Linux shell script - TecAdmin
Bash Shell, Linux Commands bash, read, script
Command:
# read var
# read -s “Waiting for input: ” var
Uses:
read command is used for getting user input in a Linux shell script. -pswitch with read command is used for showing some helpful text on-screen. Create a shell script named input.sh and add following content.
#!/bin/bash read -p "Enter Your Name: " username echo "Welcome $username!"
Lets execute the shell script
# sh input.sh Enter Your Name: Rahul Welcome Rahul!
Input Password in Shell Script
If you want to take input of password in shell script. You must want to not to show any character on-screen entered by user. Use -s for silent mode. Using -s input characters are not echoed.
#!/bin/bash read -s -p "Enter Password: " pswd echo $pswd
本文介绍了在Linux shell脚本中获取用户输入的方法。使用read命令可获取输入,-p选项能显示提示文本。还提到在脚本中获取密码时,用 -s 选项开启静默模式,使输入字符不显示。

被折叠的 条评论
为什么被折叠?



