04 October 2007

The Shell

The shell is a fundamental piece of software no matter what operating system you use (Linux, Windows, Macintosh, BSD, etc.). If you are at the command line, you are using the shell. It's that simple. In Linux, the most common shell is Bash. Bash is an abbreviation for "Bourne-again shell", with "Bourne" referring to the original UNIX shell, which is called the "Bourne shell". There are several other shells used in Linux (zsh, csh, etc.) but they aren't as common, and I've never used them. Bash is a wonderful shell. It has many, many useful features. I'm just beginning to understand this for myself, since I've only been using Linux for about 10 months. If you google "bash shell", you'll find a million resources. Wikipedia has a sizeable documentation on Bash as well. Anyway, here are a couple of interesting tidbits... At the command line on a Linux machine, to verify that you are using the Bash shell, you can type in the following command and press enter. echo $BASH_VERSION If it displays output (the version number of Bash), then you are currently using Bash. Here is the output when I enter this command on my machine: [patrick@computer ~]$ echo $BASH_VERSION 3.2.25(2)-release This means I am currently running Bash 3.2.25 (the latest version). *** One very useful Bash shortcut is what I call "tab expansion." Let's say there is a folder named examples in your current working directory. Also suppose that your current directory contains no other files or folders that begin with the letter e. Now, at the command line, type cd, space, then type the letter e and press TAB. You will notice that Bash completed the folder name for you. Pretty sweet, huh? Instead of typing the letters e, x, a, m, p, l, e, and s, you only had to type e and TAB. If you use Bash a lot, this shortcut is a huge timesaver. Let's consider one more example: Your current directory contains two folders named mail and old-mail and one file named mail-config.txt. You want to open mail-config.txt, so type nano, space, the letter m, and then TAB. Now you should see something similar to this on your screen: [patrick@computer ~]$ nano mail TAB did not complete the file name because there is also a folder in your directory named mail, so Bash does not know whether you are referring to the folder, mail, or the file, mail-config.txt. In order to complete the file name, you must now type a hyphen (-) followed by TAB. Since there are no files or folders in the current directory that begin with mail-, TAB will successfully fill in (or "expand") the rest of the file name. In a nutshell, this is how "tab expansion" works. It is easier to understand by experimenting with the TAB key while using Bash. I will save additional Bash shortcuts and tricks for a future post. Thanks for reading!

1 comment:

Anonymous said...

I learned so much from this latest blog, even though I only read the first few sentences. Keep up the good work.