Professional Documents
Culture Documents
Question 2 (4 points)
Write a shell script that accepts no command line arguments. The script reads three
integers from the standard input. If the three integers are in an ascending order; it prints
the median number and quits
If the three numbers are not in an ascending order, it displays NO and proceeds to read
three integers and repeat until three ascending numbers are read; then it displays the
median number and quits.
for example
CPU % q22.sh
334
NO
362
NO
345
4
CPU%
Question 3 (6 points)
Write a bash script that takes no command line arguments and reads one number from the
standard input with no prompt. If there is a command line argument, it displays
No command line arguments please, and proceed to read one integer.
If the integer read could be the diagonal of a right angled triangle with the other two sides
are integers, then it prints YES, otherwise prints NO on the standard output.
CPU % q23.sh 17
No command line arguments please
7
NO
CPU%
CPU % q23.sh
5
YES
CPU%
Some Functions you might need
Positional Parameters
1. if [ <condition> ]
2. then
3. statements
4. elif
5. then
6. statements
7. elif
8. then
9. statements
10. else
11. statements
12. fi
1. while [ condition ]
2. do
3. ……
4. done