Getting my shell scripts under control
#128 Henry, Tuesday, 08 May 2012 3:00 PM (Category: UNIX Tools)
(Tags: bash script)

I have a whole bunch of really messy bash scripts to do a lot of things. These scripts control my cd ripping and encoding and organisation, and my video ripping. They help me backup and transfer data. They are simplistic and they are out of control.

For example, I have a pair of scripts called music2trap and trap2music. The first one will rsync my /music directory (where I have all my mp3s) with a mount point where my mp3 transfer external hard disk is attached. The second one is for work when I attach the external hard disk and sync it with the /music directory at work.

They work. But it sucks because I can't remember what things are, where the mount point is, and if the mount point changes (like the external mounts as /mnt/sde for various reasons) I have to make a temporary change, then forget to change it back, or I create a one-off copy of it, or anything else.

So I got sick of all this. I decided it was time to do the right thing by ALL my shell scripts. I started with this pair. I renamed them more sensibly. I don't know why they ended up with trap in the name. So now they are music2ext and ext2music.

Both use command line switches for over-rides.

And now I plan to do the same to all my scripts. Every time I have to use one of my shell scripts, I am going to take it apart and rebuild with these points:

I read about doing this a long time ago in a book about bash scripts, but it took me this long to understand why you do a decent job of even throwaway scripts. Because throwaway scripts turn into long-standing and often used scripts.