Monday, December 12, 2005

You Can Invoke the Shell By Hand

You invoke a shell the same way you invoke any other program: type its name.

bash
You get back a prompt, but now this is a second shell, a subshell under the previous shell. The shell you were running a minute ago is now patiently waiting for this subshell to finish, so it can put up another prompt and let you issue some other command.

See for yourself? Type exit. You'll exit this subshell, and return to the shell a level up. You're back in the shell you started from.

Want more convincing? Type history. That's your current shell. Now execute a subshell, and look at the history again:

bash
history
Finally, exit the subshell, and look at the history again:

exit
history
You get two different histories because it's two different shells.

If you execute commands, then spawn a subshell, and then try to recall the commands you were just executing before you entered the subshell, you won't find them.

It's important that you have a firm grasp on the idea of subshells before you continue, so I'll return to this, tomorrow.

0 Comments:

Post a Comment

<< Home