home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Unix Power ToolsUnix Power ToolsSearch this book

29.6. zsh Aliases

zsh has the regular command alias covered in Section 29.4. zsh is compatible with the C shell in many ways, but it doesn't accept csh alias syntax without an equal sign (=) between the name and value. That's probably because, as in other Bourne-type shells, zsh allows you to set multiple aliases with one command, like this:

zsh$ alias ri='rm -i' mi='mv -i'  ...and so on

In zsh, alias -g defines a zsh global alias: a word that's expanded anywhere (as long as it isn't quoted). These are like a shell variable (Section 35.9) that doesn't need a dollar sign ($) to be expanded. Maybe you have a log file you read and edit often. You could make a global alias named log:

zsh$ alias -g log=/work/beta/p2/worklog

zsh$ less log
zsh$ cp log logtemp

Global aliases are expanded only when they stand alone and aren't quoted. So if there's a global alias dir for a directory, you cannot use emacs dir/file to refer to a file in that directory. Also, if you defined the global alias fserv for the hostname fserv.bkk.ac.uk, you could type telnet fserv -- but if you type mail ed@fserv, the shell wouldn't expand it into a hostname. Named directories and shell variables work better in cases like those.

alias -m lists aliases that match a wildcard-type pattern; alias -m 'hi*' shows all alias names that start with hi (like hi, hist, and so on). This matches regular command aliases as well as global aliases. You can use -m with unalias, too, to remove all aliases matching a pattern.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.