Monday, March 22, 2010

Verifying which shell you are running

Because there are many shells available, it is important to learn to distinguish between the different shells. Typing commands for one shell when you are using another is bound to cause confusion. I know from personal experience. This was aggravated by the fact that many books I used to learn UNIX never mentioned that other shells existed. Therefore, the first step is to make sure you are using the proper shell.
You can execute the following command to determine your default shell (The command you type is in boldface):
% echo $SHELL /bin/csh
While this identifies your default shell, it does not accurately identify the shell you are currently using. I will give you a better way to find out later. Because this column discusses the Bourne shell, any commands discussed here will only work right if you are using the Bourne shell. You have two choices: place these commands in a Bourne shell script. That is, create a file, make the first line read
#!/bin/sh
Make the second line, and those following, contain the commands you want to test. Then make it executable by typing
chmod +x filename
Once you do this, you can test the script by typing
./filename
The second method is to create a new window (if you desire). Then type
sh
You may see a change in the characters the shell gives you as a prompt, like the example below:
% /bin/sh $
The Bourne shell will execute each line you type, until an end of file is found. To put it another way, when you type Control-D, the Bourne shell will terminate, and return you to the shell you were previously using. This is the same action the shell takes when a script file is executed, and the end of the script file is reached.

No comments:

Post a Comment