Home > Article > Operation and Maintenance > How to prompt user for input in Linux shell script
This article will introduce to you how to prompt user input in a Linux shell script? Let’s look at the specific content below.
Let’s first look at the command
# read var # read -s “Waiting for input: ” var
Purpose:
The read command is used to obtain user input in a Linux shell script. The -p switch with the read command is used to display some useful text on the screen. Create a shell script named input.sh and add the following content.
#!/bin/bash read -p "Enter Your Name: " username echo "Welcome $username!"
Let’s execute the shell script
# sh input.sh Enter Your Name: admin Welcome admin!
Enter the password in the shell script
If you want to enter the password in the shell script. Do not display any characters entered by the user on the screen. Use -s to indicate silent mode. Characters entered using -s will not be echoed.
#!/bin/bash read -s -p "Enter Password: " pswd echo $pswd
This article has ended here. For more other exciting content, you can pay attention to the Linux Tutorial Video column of the PHP Chinese website!
The above is the detailed content of How to prompt user for input in Linux shell script. For more information, please follow other related articles on the PHP Chinese website!