z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Setting up an alias for a particular version of a command

z/OS UNIX System Services User's Guide
SA23-2279-00

If you tend to use a command with the same options every time, you may want to set up an alias for the command with those particular options. Let's take an example. The grep command searches through files and prints out lines that contain a requested string. For example:
grep hello file
displays all the lines of file that contain the string hello. Normally, grep distinguishes between uppercase and lowercase letters; this means, for example, that the search in the previous example does not display lines that contained HELLO, Hello, and so forth. If you want grep to ignore the case of letters as it searches, you must specify the –i option, as in:
grep -i hello file
This finds hello, HELLO, Hello, and so on.
If you think you prefer to use the –i version of grep most of the time, you can define the alias:
alias grep "grep -i"
From this point on, if you use the command:
grep string file
it is automatically converted to:
grep -i string file
and you get the case-insensitive version of the command grep.
As another example, the rm command to delete (remove) a file has an –i option that prompts you to confirm the deletion. The file name and a question mark are displayed. For example, if you entered rm -i file1 and file1 is in your working directory, you would see the prompt:
file1: ?
before the system actually removes the file. You then enter y (yes) or n (no) in response. If you like this extra bit of safety, you might define:
alias rm "rm -i"
After this, when you call rm, it automatically checks with you before deleting a file, just to make sure that you really want to delete it.

It may seem odd to define an alias that has the same name as a command that is used in the alias, but this is so common that the shell checks specially for an alias of the same name, and does the correct thing.

If you find yourself using the same option every time you call a command, you might consider creating an appropriate alias so that the shell automatically adds the option. Of course, the best place to define this alias is in your .tcshrc file; then the alias is set up every time you invoke the shell.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014