-->

How to prompt for User Input in Linux shell script

Author Piyush Gupta

Command:

# read var

# read -s “Waiting for input: ” var

Uses:

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: Piyush
Welcome Piyush!

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

No comments:

Post a Comment