Archive for the ‘8 - Shell hell’ Category

VIII – Shell hell

onsdag, juni 23rd, 2010

Shell scripting is my one true love in life besides cocain. It wasn’t love at first sight, though. You see, there is a threshold to be conquered before you can truly enjoy the shell in its only form – simple, honest, definite. But once you’ve climbed that mountain the view cannot be matched by any other programming language I’ve experienced. There are no fancy pancy util classes, code standards or design patterns. There is just raw, untamed bash. It cannot be forced but merely twined into patterns of desired functionality. And yet I have so much more to learn.

But let’s take it from the beginning. Before a user interface (UI) there was a shell – a command line interpreter. In linux this shell is still very much used and is, despite its name, more flexible than a UI could ever be. A graphical window view of the system is very useful from time to time though. In Linux there are a couple of shells that can be used. They are pretty similar. The most used, most advanced, and the most recent is the bash-shell (Bourne Again SHell). You can find the current shell you’re using by typing   ‘echo $SHELL’ in a terminal.
The file ‘/etc/shells‘ contains all of the shells available to you (‘cat /etc/shells’). Your default shell is probably set in your ‘/etc/passwd‘ file (this file contains one line entry for each account on the system and is, by the way, also used to set the $HOME path for each of these accounts). Preferable you want ‘bash’ to be your default shell. You can always change the current shell by typing the name ’sh’ or ‘bash’ or some other shell in your local terminal.
As we’ll see in chapter ‘IX – Scripting’ arrays are support in bash but not in e.g. sh.