Hour 12
1: | What changes are required to the following while loopx=0 while [ $x -lt 10 ] do echo "$x \c" y=$(($x-1)) x=$(($x+1)) while [ $y –ge 0 ] ; do y=$(($y-1)) echo "$y \c" done echo done so that the output looks like the following: 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5 6 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 9 |
A1: | Here is one possible implementation:
x=0 while [ $x -lt 10 ] do x=$(($x+1)) y=0 while [ $y -lt $x ] ; do echo "$y \c" y=$(($y+1)) done echo done |
2: | Write a select loop that lists each file in the current directory and enables the user to view the file by selecting its number. In addition to listing each file, use the string Exit Program as the key to exit the loop. If the user selects an item that ... |
Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.