Prompts are used get the output based on the user input. You can use the read command in your Linux shell script to prompt for Yes/No/Cancel input from the user. Here's an example script that demonstrates this:
#!/bin/bash
# Prompt the user for input
read -p "Do you want to continue? [Y/n/c] " input
# Process the user's input
case "$input" in
y|Y)
echo "You chose to continue."
;;
n|N)
echo "You chose to cancel."
;;
c|C)
echo "You chose to cancel."
;;
*)
echo "Invalid input. Please choose Y, N, or C."
;;
esac
In this script, the read command prompts the user to enter their input with the message "Do you want to continue? [Y/n/c]". The -p option is used to specify the prompt message.
The user's input is then processed using a case statement. If the user enters "y" or "Y", the script prints "You chose to continue." If the user enters "n" or "N" or "c" or "C", the script prints "You chose to cancel." If the user enters any other input, the script prints "Invalid input. Please choose Y, N, or C."
Comments (0)