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

How do I prevent Zshell (and Bash I assume) from expanding environment variables in paths be completed as shown in the following example:


should expand to


and not to say

share|improve this question
up vote 1 down vote accepted

This is the default behavior under zsh. The complete-word and expand-or-complete zle widgets don't expand parameters whose value is a directory name, as long as there's a / after it (i.e. $foo/<TAB>).

There are many ways to customize this behavior. For example, maybe you've set up Tab to run expand-or-complete-prefix. There are also styles such as expand and keep-prefix that affect this behavior as well.

share|improve this answer

Assuming you have a literal directory called $PREFIX, just prepend a \ before the $, for \$PREFIX, then your tab completion will work. If you don't have a literal directory called $PREFIX, then autocomplete will not work, because it needs to expand $PREFIX in order to determine what values are valid for the autocompletion.

share|improve this answer
This is not what I want. $PREFIX is not a literal directory but an environment variable PREFIX whose value is /opt which I want to use in path completion. However, I don't want it to be expanded to /opt by the shell during completion. – Nordlöw Sep 26 '12 at 13:31
The I amend my answer to "No. There is no way to suppress expansion of any type of variable during auto-completion." – Tim Kennedy Sep 26 '12 at 13:44

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.