Read command takes the input from a user and saves it onto a variable, so you can use it later on during your script.
Ask a user to press Y
or N
to execute.
-
read
is a command to ask user to give answer or press a key to continue. -
-p
means to write a message which user can see, andanswer
is your variable.
1
2
read -p "Would you like to proceed? [y/n]: " answer
echo "$answer is pressed!"
Ask a user to type the password in hidden mode. -s
means secret which cannot be displayed on the user’s screen. But you can save the password on the variable for future use. May be your script requires a password before execution.
1
2
3
read -s -p "Please type your Password: " pass
echo
echo "this is your password $pass"