Run these commands:

[$] echo 'export VAR="qwertyuiop"
export VAR="$VAR:asdf=ghjkl"' > /tmp/vars.sh
[$] source /tmp/vars.sh
[$] echo $VAR

As you can see, the variable substitution does not do what we expected. What is the issue here?


The colon works as a modifier in zsh. Quoting this reference,

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a ‘:’. These modifiers also work on the result of filename generation and parameter expansion, except where noted.


Turn a file name into an absolute path: prepends the current directory, if necessary (...)

All in all, the :a works as a modifier and prepends the current directory to VAR expanded value.

In order to prevent the modifier from acting, enclose the variable in curly braces: VAR="${VAR}:asdf=ghjkl".

| improve this answer | |
  • Note that those $var:x modifiers (though not that a one specifically which is a zsh extension) come from csh. bash supports them as well, but only for history expansion (like !$:t), not for parameter expansion ($_:t). – Stéphane Chazelas Mar 3 at 15:00
  • Note that if the ksharrays option is enabled, braces are required for those modifiers to be recognised ($var:t is then like ${var}:t, you'll need ${var:t}). Not that you'd want to enable that option, but that means the problem won't show up when zsh is running in sh or ksh emulation where that option is enabled. – Stéphane Chazelas Mar 3 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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