Bash Shell Scripting

One of the best things about Linux is the ability to write shell scripts. These are most often used as utility programs to do repetitive tasks for you. I just wrote my first one on Sunday and here it is followed by commentary.


echo "starting xchat..."

echo "starting Gaim..."

echo "starting Thunderbird..."

echo "starting Gkrellm (docked)..."
gkrellm -w&

echo "starting 2 instances of Eterm (transparent, no buttonbar, no scrollbar)"
Eterm -x --scrollbar=0 --buttonbar=0 --trans&
Eterm -x --scrollbar=0 --buttonbar=0 --trans&

The first line is required in any bash script. On the second line I am using the echo command to write stuff to the screen. This is just to remind me of what exactly the script is doing. This could be important if I write another startup script that launches different programs.

Why did I write this script? I wrote this script because I was starting up these programs every time I started up my computer. While a Linux computer barely ever needs to be rebooted, I still wanted to be able to type just one command instead of six. Additionally, I didn’t memorize the command to make the Eterm window look like I wanted. Instead of scrolling through all my commands every time I wanted to launch up an Eterm window, I coded it in. In fact, if you like how my Eterm windows look, you could write a script called “Transparent Eterm” and run it to start them up instead of typing that long statement every time.

I’m sure there’s some way to launch programs at startup in Linux, why not use that? A very simple reason: I don’t want it to startup every time. Back when I was really into Windows I put some programs into the “Startup” folder that I thought I would use every time I launched the computer such as AIM and WinAmp. Then came a day when the computer was misbehaving and I had to reboot it a few times. Waiting each time for all those programs to load that I didn’t want to load because I was doing diagnosis was very annoying. Thus, by writing this script (which currently can’t be done in Windows) I am able to launch all the programs I use at startup, but only when I want them up.

Other things you should know:

  • when you write a script you need to make it executable. If you are the only user on a system the easiest way to do this is to do:
    vi scriptname
    to write the script and
    chmod 777
    to make it executable. Of course, everyone can execute your script now, but if you’re the only one it doesn’t matter
  • you need to type
    to launch the script.
, , ,