Write the program using an if command and then rewrite it using a case command. This program can be useful when reading yes/no responses from the terminal.
Write a program called isyes that returns an exit status of 0 if its argument is yes, and 1 otherwise. For purposes of this exercise, consider y, yes, Yes, YES, and Y all to be valid yes arguments:
$ isyes yes
$ echo $?
0
$ isyes no
$ echo $?
1
The first version with the if conditional is:
if [ -n "$( echo $1 | grep -E '(^[Yy][Ee]{0,1}[Ss]{0,1}$)')" ] ; then
exit 0
else
exit 1
fi
And the second version with the case statement is:
case "$1" in
[Yy][Ee]{0,1}[Ss]{0,1} ) exit 0 ;;
* ) exit 1 ;;
esac
You might also like to view...
A network administrator is tasked with deploying a company-wide wireless system which allows for accurate tracking of employees' wireless device locations via WAP triangulation. Which of the following is the MOST important aspect of the deployment?
A. WAP placement B. TX/RX channel C. Signal strength D. Transmission power
?What is the frequency range of the C-band that is used by satellites?
A. ?1.5 - 2.7 GHz B. ?2.7 - 3.5 GHz C. ?3.4 - 6.7 GHz D. ?12 - 18 GHz