Linux Tweaks, HowTo's and Reviews

Last time in Bash to Basics I showed how to print text to the terminal with the echo command. This got me thinking about the first program I wrote when I was in fourth grade. I was fortunate enough to be in a school district that had computers in the early '80s. If you're around my age, then you may remember the mighty Commodore PET computer.

Some of us were put into a program to learn BASIC programming. The first program we were taught to write made a rocket ship fly up the screen by using Print statements. It looked something like this:

Save the above text as a script called rocket1 and make it executable with:

chmod +x rocket1

You can now run this script with the command:

./rocket1

Now on the old PET computers, this type of program worked pretty well. You got a nice effect of a rocket ship flying up the screen. Most likely your computer is fast enough that the rocket just appears instantaneously in your terminal window, so we need to figure out how to slow it down a bit.

This is a perl command that will pause a program to allow for user selection. The fourth parameter is the timeout time of 0.4 seconds. The rest of the selection parameters are left undefined. Let's try inserting some of these commands into our program.

Save this as rocket2 and make sure to make it executable with the chmod command.

Running this script works a little better. Notice how the changes in the delay time create a nice acceleration effect.

Not satisfied to leave well enough alone, I wondered if I could create a countdown before the rocket launch. I was able to do it by using some of the advanced options of the echo command. Here's what I came up with.