So the short story is I got a small UPS for my tv, xbox and cable modem so that I won’t be interrupted by small power hiccups. I decided I wanted to know how long my CRT tv and xbox would continue while watching a movie so I needed something to count with while I unplugged the power to test it.
Now I’m sure others have written scripts and I could probably have just used the clock on the computer but I decided it couldn’t be too difficult to figure out how to write a script to do this. I knew that I basically had to just create a loop that would print a number increasing by one and then wait one second and repeat. I just had to find the right commands. About 10 to 15 minutes of searching later and I had this:
#A very basic time counting script.
#init value of x
#make y 1 less than x
echo "Counting from $y..." #Output what number we are beginning from
while [ $x -ge 0 ] #While $x is >= 0 (all the time)
sleep 1 #Wait one second
echo $x #Echo value of $x
x=$((x+1)) #Increase $x by 1
Some of the methods are a little different from what I am used to. To increase $x by 1, I am used to $x++. Bash is different I guess. There may be simpler ways to do this as well. If so, please leave a comment as I’m hopeful to learn.
Counting from 0...
Also note this script will continue to run until the user types the escape sequence ‘Ctrl+C‘.
Some sources used to find what I needed:
- http://www.cyberciti.biz/tips/linux-unix-pause-command.html – Actually found the sleep command in the comments. Excellent site!