# read var
# read -s “Waiting for input: ” var
read command is used for getting user input in a Linux shell script. -p switch 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