Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have searched around but could not find anything conclusive. Is there a difference between the alias command in zsh and the alias command in bash? If not, does it mean I can share a set of aliases between the two shells and expect them to work as I intended?

share|improve this question
up vote 5 down vote accepted

According to the Zsh Workshop Aliases they seem to have the same syntax, so they should work.

share|improve this answer
I can attest to that. The do for me. – frogstarr78 Nov 24 '11 at 5:17

The syntax of the alias command is the same in all Bourne-style shells. So you can share them across ~/.zshrc, ~/.bashrc, ~/.kshrc, ~/.shrc, as long as they make sense in all the shells.

The same holds for variable definitions and function definitions, as long as you use the subset of syntax that's supported in all shells.

If you don't use versions of zsh older than 4.0, you can put all your shell-agnostic definitions in a file called (say) ~/.common.rc.sh, where the first line is

emulate -LR sh 2>/dev/null

This tells zsh to expect sh compatible syntax in this file only. Then source that file near the beginning of ~/.bashrc, ~/.bashrc, ~/.kshrc and so on.

This is basically what I do. For example, I have somewhat complex code that generates an alias for ls with my favorite options depending on what's available (--color, -G, -F, etc.); it's shell-agnostic, so goes in .common.rc.sh. I also have shell-dependent aliases, like alias zcp='zmv -C' that goes in .zshrc.

share|improve this answer
If I put a /bin/sh shebang at the top of my aliases file will it work as I intend for all shells? – Zameer Manji Nov 25 '11 at 13:08
@ZameerManji No, don't put a #! line: this is not a standalone script, it can only be sourced in another script. #! doesn't change the shell's behavior anyway. – Gilles Nov 25 '11 at 13:33
A tiny difference I found is that zsh's alias treats an argument beginning with + as introducing an option like - would, so alias +=something must be written as alias -- +=something in zsh. Don't think emulate changes that. – Mikel May 11 '12 at 1:09

Your Answer


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.