Transfered from Linux Config:
Question:
Hi,
I have a question for my bash scripting.
Can you help me by this script?
Thanks Chris
(Modify countdown such that it prompts user for a starting value, and counts down from there.
Write a script called countdown2 that accepts the initial value as a command-line argument. For example, the command and its output might look like the following.
Answer:Code:$ ./countdown2 12 12 11 10 9 8 7 6 5 4 3 2 1 GO!
Probably the easiest way to do count reverse in bash is to use while loop. Save this script as countdown2, make it executable and run:
Output:Code:#!/bin/bash COUNT=$1 # bash while loop while [ $COUNT -gt 0 ]; do echo $COUNT let COUNT=COUNT-1 done echo GO!
Code:./countdown2 4 4 3 2 1 GO!


Reply With Quote
