bash script using the case conditional statement.
-
Take into account the main readme for this section. README first.
See the The GNU bash documentation for more test operators at: https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html
Code.
$ cat learnbash.sh #!/bin/bash read -p "Would you like to go to the ball with me? y/n : " Answer case $Answer in Y|y) echo "Woohoo, I got a date!";; N|n) echo "Very well, a pleasure..";; *) echo "One is dining alone";; esac
Run the script.
$ ./learnbash.sh Would you like to go to the ball with me? y/n : n Very well, a pleasure.. $ ./learnbash.sh Would you like to go to the ball with me? y/n : y Woohoo, I got a date! $ ./learnbash.sh Would you like to go to the ball with me? y/n : One is dining alone
© Lightnetics 2024