The Well-Groomed Login

We've covered a variety of customizations you can do in your login to make Unix more livable. It's time to bring them all together in one place. As is usual in these Tipsheets, the comments most generally refer to the Korn shell, since all Bama users are given this this by default.

Don't Get Bitten by "rm"

You definitely don't want to delete your entire account with one slip of the keyboard, so let's get the "rm" command reined in (Tipsheet Vol. 1, No. 3). Add this line to the end of your ".profile" file:

export ENV ~/.kshrc

and create a new file in your home directory call ".kshrc". Put this into ".kshrc" using the editor of your choice:

alias rm='rm -i '

Now whenever you go to remove a file, you will be asked "yes or no" about the deletion before it is completed.

Don't Get Clobbered Either

In Tipsheet Vol. 2, No. 13 we showed you how to append one file to another in Unix. The trick was to use output redirection with ">>". The hidden danger was that if you typed only one greater-than symbol you would overwrite the file instead of appending to it. To prevent this you needed to put

set -o noclobber

in your ".kshrc". Now you will not be allowed to write one file write on top of one another without explicitly telling Unix to do so. How do you force Unix to overwrite? In the Korn shell you can't. You'll have to delete the unwanted file and then copy over the new information into it.

Does Delete Mean Backspace or Vice Versa?

Unix has a great deal of keyboard flexibility. The result is that you never know what you're going to get when you press certain keys. The usual problem-key is getting a deleting backspace. Different Telnet programs will send different signals when you press the backspace or delete key. Some Telnet's even let you change the character that is sent. The trick is to get Unix to recognize whatever is sent as the real delete. At the command prompt you should type

stty erase deletekey

where deletekey is the key you want to have as your delete key. The only requirement is that the key sends one character when you press it. If you test this out and find that the key seems to send several characters in a row, this will not work. Now once you have done this, that key will be the delete key for the remainder of your login session. To have it come up as the default you need to put the stty command in your ".profile". When you type this command at the prompt, note which characters appear when you press your desired delete key. Those are the characters you will put in ".profile" for the stty command. For instance, if your desired delete key sends a control-H, which will show up as "^H", then in ".profile" you will put the literal "^" and "H". So the ".profile" line will be

stty erase ^H

That is probably the most common erase character code but occasionally you will see "^?".

Don't Get Control-d'd Out

In Tipsheet Vol. 1. No. 3 we told you how control-d is a synonym for exit (logout). It is quite easy to type this by accident. Those of us with "fat typing fingers" know the confusion felt when we are logged out "for no reason." So add this line to the end of ".kshrc".

set -o ignoreeof

Use Initialization Files

In Tipsheet Vol. 3, No. 4, we showed you how to use initialization files to customize your setup. You can save time by putting your favorite startup options into initialization files or environment variables, if available. The purpose of these files and variables is to make your life easier, so use them.

Don't Do More Than You Have To on Startup

In Tipsheet Vol. 3, No. 3 we talked about keeping your ".kshrc" file from slowing down the execution of all commands. This file gets read every time a new shell starts up, which is just about every time you run a command. If your ".kshrc" grows large you will start to slow down the execution of all your commands. To stem this behavior you should put a test in your ".kshrc" which will cause it to exit if it is not being run for an interactive shell. Then, after the test, put in the lines that make sense only in an interactive setting (which may be most of the commands). Here are the lines that do the test:

case $- in
*i*);;
*) return 0;;
esac

 

Well, these are the top of the list of things you should do to make you login safe and effective. As you become comfortable with what you have done here you can add more to your customizations, including aliases and initializations, so that you have a pretty powerful setup.

 

© 1999, The University of Alabama. The information included here is for the University of Alabama central computing facility as it was configured on the document date. It may or may not apply to other Unix systems.