O'Reilly logo

Learning the Korn Shell, 2nd Edition by Bill Rosenblatt, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Aliases

Perhaps the easiest and most popular type of customization is the alias, which is a synonym for a command or command string. This is one of several Korn shell features that were appropriated from the C shell.[33] You define an alias by entering (or adding to your .profile) a line with the following form:

alias new=original

(Notice that there are no spaces on either side of the equal sign (=); this is required syntax.) The alias command defines new to be an alias for original; whenever you type new, the Korn shell substitutes original internally. (You cannot use any of the shell’s special characters, such as *, $, =, and so on, in alias names.)

There are a few basic ways to use an alias. The first, and simplest, is as a more mnemonic name for an existing command. Many commonly used Unix commands have names that are poor mnemonics and therefore are excellent candidates for aliasing; the classic example is:

alias search=grep

grep, the Unix file-searching utility, derives its name from the command “g/re/p” in the original ed text editor, which does essentially the same thing as grep. (The regular expression matching code was carved out of ed to make a separate program.)[34] This acronym may mean something to a computer scientist but probably not to the office administrator who has to find Fred in a list of phone numbers. If you have to find Fred, and you have the word search defined as an alias for grep, you can type:

search Fred phonelist

Another popular alias eschews ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required