UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 5: Account Management |
|
||||||||||||||||||||||||||||||||||||
|
There is an unobtrusive way to change a shell without affecting the password file in any way.
Flavors: AT&T, BSD
Shells: ksh, sh
You know that using the chsh command physically changes the password file to the shell of your choice. That command also only permits shells that are listed in the /etc/shells file. So what do you do if you want to use the bash shell and it isn't listed? There is a way around it: The following seven lines of code for the .profile startup file will have you using the bash shell every time you log in or open a new window to a shell:
if [ -x /usr/local/bin/bash ]; then SHELL=/usr/local/bin/bash export SHELL exec /usr/local/bin/bash else echo /usr/local/bin/bash not found using default shell of $SHELL fi
Line 1: Verify that the bash shell exists and is executable.
Line 2: If it does exist, set the variable SHELL to /usr/local/bin/bash.
Line 3: Export the variable globally.
Line 4: Start the bash shell
Line 6: If there was no bash shell, you have to use your default shell assigned to your account.
This concept can be applied to other shells with some minor changes to the syntax. Although this is good for your personal account, it is just as good for the root account if you are more comfortable working in a different shell as root. It works so well for root that, when you need to drop into single-user mode, the shell will not be located because the mount point most likely is not mounted in that mode, and the normal root shell takes over.
Everyone has a shell of choice, and this allows its use. It is unobtrusive and satisfies the needs of both the administrator and the user.
This common little hack works well when it's embedded into the startup files. Also, other conditions besides the shell can be tested this way to see whether you are on a local or remote system and to execute specific commands. It gives your users freedom to start processes when they log in to a system and, when they log out, to stop them.
UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 5: Account Management |
|
||||||||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.