When you log in to most UNIX systems, your shell is a login shell. When a shell is a login shell, it acts differently. For example, the shell reads a special setup file (2.2) like .profile or .login. UNIX "knows" how to tell the shells to be login shells. If you type the shell's name (like sh or /bin/csh) at a prompt, that will not start a login shell.
Sometimes, when you're testing an account or using a window system,
you want to start a login shell without logging in.
UNIX shells act like login shells when they are executed with a name that
starts with a dash (-
).
[1]
The easiest way to do this, which wastes a lot of disk space (and may not
work on your system anyway if the shells are read-protected), is to make
your own copy of the shell and name it starting with a dash:
[1] bash also has a command-line option, -login, that makes it act like a login shell.
bin ./- | $ |
---|
It's better to make a symbolic link (18.4) to the shell:
$cd $HOME/bin
$ln -s /bin/csh ./-csh
(Or, if your own bin subdirectory is on the same filesystem as /bin, you can use a hard link (18.4).) A third way is to write a little C program (52.8) that runs the actual shell but tells the shell that its name starts with a dash. This is how the UNIX login process does it:
main() { execl("/bin/csh", "-csh", 0); }
No matter which way you choose, you can execute your new shell by typing its name:
$-csh
...normal C shell login process... % ...run whatever commands you want... %logout
$ ...back to original shell
Article 2.16 shows how this can be used to change your normal login shell.
-