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