09/countdown.sh (35 points) + Write a script which gets one parameter: number of seconds (nonnegative integer) to count

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

09/countdown.sh (35 points) + Write a script which gets one parameter: number of seconds (nonnegative integer) to count

Post by answerhappygod »

09 Countdown Sh 35 Points Write A Script Which Gets One Parameter Number Of Seconds Nonnegative Integer To Count 1
09 Countdown Sh 35 Points Write A Script Which Gets One Parameter Number Of Seconds Nonnegative Integer To Count 1 (291.41 KiB) Viewed 34 times
09/countdown.sh (35 points) + Write a script which gets one parameter: number of seconds (nonnegative integer) to count down, and each second it prints time left. You can safely assume that the program will be invoked correctly under all circumstances. If user hits Ctrl-C during execution (or sends the TERM signal), the script aborts by printing the word Aborted and exits with the status of 17. Example: $ ./countdown.sh 10 10 9 8 7 6 5 4 3 2 1 Each line will appear a second after the previous one. Use sleep 1 to wait between printing the lines and before exiting. Therefore, the first number is printed immediately, whereas after the final line with 1 you still have to wait before your script terminates. Note that the script will be a little bit slower than the requested time in seconds (because of the overhead of calling the sleep command itself) but that is fine. Example execution when user hits Ctrl-C is as follows (™C denotes the place where the user hit Ctrl-C and is not an output from your program). Note that the FAILED message comes from the echo and serves only to emphasize the non-zero exit code. $ ./countdown.sh 5 || echo "FAILED" 5 4 AC Aborted FAILED
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply