Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know that in bash you can set up aliases in a .bash_aliases file so that the command you type doesnt need to be a command stored in the binaries in the system. Is there any way I can get aliases into zsh?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

you can do it by the "alias" command with this syntax:

alias [ -gmrL ] [ name[=value] ... ]

for "gmrL" switchs, see this guide, which is my reference. For each name with no value, zsh will print the name and what it is aliased to previously. With no arguments at all, alias prints the values of ALL defined aliases.

To define one or more aliases, simply enter

alias name1=value1 name2=value2 ... nameX=valueX

For each name with a corresponding value, zsh defines an alias with that value. for further info, check out that link ;-)

Update: updated the dead link.

share|improve this answer
    
That document answered my question exactly. Thanks much. –  Thomas W. Mar 21 '11 at 3:22
    
That link is down. –  Soham Chowdhury Apr 14 at 10:52
    
updated the link. –  sazary Apr 14 at 17:54
    
this answer misses the part about where to persist the aliases, Kurtosis answer includes it (.zshrc). –  Felix Jul 31 at 9:06

You generally put them in ~/.zshenv. But many programs use /bin/sh (usually bash) instead of $SHELL to execute shell commands, so for it to work everywhere you will probably need to put the bash equivalent of the alias into ~/.bash_aliases anyway.

share|improve this answer
    
This is for my user account only, so this does not need to be copied to the ~/.bash_aliases file. –  Thomas W. Mar 20 '11 at 18:02

I go back and forth between bash and zsh, and use the same .aliases file for both. They share the same basic alias syntax, so you can create a .aliases file and link it to .bashrc and .zshrc:

.bashrc:

if [ -f ~/.aliases ]; then
    . ~/.aliases
fi

.zshrc:

source $HOME/.aliases

Fwiw this can also be done with environment variable declarations, in a separate .env file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.