Pages

Tuesday, October 27, 2009

Bash Scripting, again

I do very little Bash scripting, since my primary language is PHP. But, for some reason whenever I start writing bash stripts, I get a rush that I don't get from any other languages. Maybe it's the feeling of trying to be a UNIX geek or maybe it is a way of harkening back to batch files in DOS land (only better). I can't explain it. One idea I have as to this phenomena is that there are so many mechanisms to use when shell scripting. AWK, sed, regular expressions, bc, and of course the infinite bash native syntax available makes UNIX scripting the best.

Since I very seldom use bash scripting, I am constantly googling to find the correct syntax for what I am trying to do. This last time, possibly due to the complexity of what I was trying to do, I found some notable sites.

http://www.injunea.demon.co.uk/pages/page205.htm - This site appears to have many pages, but for some reason, this is the page I always seem to land on when searching. Really good explanation of for, while, and if structure right at the beginning of the page, along with some other goodies.

http://bashrules.blogspot.com/2005/04/strlen-of-bash.html - Yea, I know this is the most boring of all blog entries in the history of the world, but this is invaluable knowledge and very vividly illustrates the dynamic nature of straight-up bash scripting

http://www.arachnoid.com/linux/shell_programming.html - Get your favorite caffeinated beverage, because we'll be here a while. This page shows a plethora of shell scripting syntax. Just a few examples include regular expressions, arrays, and some of the most messed up shell variables you've ever seen.

http://www.vectorsite.net/tsawk.html - Next to bash syntax, AWK is quite possibly the most useful tool in the UNIX swiss army knife. AWK is mainly useful for string comparison, but that's really the name of the game with anything from file content alalysis to program output manipulation.

This isn't an exhaustive list, but I'm sure that I'll find more cool scripting techniques in the future.