August 29, 2005

CLI Magic: Recycle your shell

Author: Joe Barr

When you're at the CLI, you're where it's at. Why else would Microsoft -- the glutton for GUI -- be slaving so feverishly to add a shell to their next release? At the risk of sounding like Yogi Berra and that duck in the barbershop commercial, I've got to say although Microsoft found replacing the DOS command line to be too tough a shell to crack, others did not, and that's why Monad is no longer on the feature list for Vista. Never fear, gentle readers, Linux has shells enough for all, and this week we'll look at two different ways to change the one you're usingThe most popular shell on Linux distributions is the Bourne Again Shell, aka bash. SUSE 9.3 Professional also includes Zsh, which resembles the Korn shell; tcsh, an enhanced, compatible version of the Berkeley UNIX C shell; and sash, a stand-alone shell with built-in commands.

Not included with SUSE, but readily available on the Internet, are the Clam Shell, whose functionality can be defined at runtime; the Perl Shell, for those who just can't leave /home without a little Perl; and finally, one of the featured tools for this week, vfsh: the shell for those who can never decide which shell to run.

Changing shells the chsh way

Now that we've piqued your curiosity, here's how you can experiment with some of those other shells. First, you need to know what shells are installed on your system. Nothing could be easier to learn. Just enter the following command at the CLI. My system responds like this:

cat /etc/shells
warthawg@linux:~> cat /etc/shells

Note: Not all distributions include all the choices included in /etc/shells. Obviously, the shell must exist on your system in addition to being in the list. On SUSE 9.3, some of the listed shells are links to others.

After picking your choice from the buffet, use the change shell command to change the shell which will run at your next login. The format for the command is chsh username. You can only change the shell for the username you're logged in as. Unless you're root, of course. Then you can change anyone's shell. Want to try csh? Enter this:

warthawg@linux:~> chsh warthawg
Changing login shell for warthawg.

After entering your password, chsh displays the current shell (/bin/bash) and prompts you for the new one. If you leave it blank and just hit return, it defaults to the current shell.

Enter the new value, or press return for the default.
        Login Shell [/bin/bash]: /bin/csh
Shell changed.

The next time I logged in, bash was gone and tcsh was in place.

Changing shells randomly

For the more adventurous, there is a different tool. It's called vfsh, and it makes a random choice of shell for you each time you log in. To use it, you'll need to compile and install the program, add an entry for it in /etc/shells, and then use chsh to select it as your default shell.

Download the source code from here, and then -- from the same directory -- tell the compiler to create an executable named vfsh. Like this:

gcc -o vfsh vfsh-1.0.c

If all goes as expected, you'll now have an executable file named vfsh in the directory. As root, move or copy vfsh to the /bin directory. Then, still as root, edit /etc/shells and add the following line:


Then, using the technique shown earlier, change your default shell to vfsh and you're all set. You'll never get bored having the same old shell around every time you log in. And, if you're not real careful, you might just learn a little more about the CLI.

Click Here!