Skip to main content
edited tags; edited title
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

Unexpected variable expansionquotes in ZSHzsh trace

Source Link

Unexpected variable expansion in ZSH

I've got a third party script that receives command line arguments in this form:

$ ./script.sh --params a=123 b=456

There is a file xyz.txt with this contents:

c=3
d=4

I'm trying to use its contents as paremeters for the script, but the script complains about not receiving proper arguments. When I do set -x, I can see that each of my arguments is enclosed in single quotes (so the third party script cannot handle them)

$ set -x
$ ./script.sh --params $(cat xyz.txt)

....
+-zsh:20> cat xyz.txt
+-zsh:20> ./script.sh --params 'c=3' 'd=4'

Tried in bash (also with set -x) and the result is as expected (no single quotes):

$ set -x
$ ./script.sh --params $(cat xyz.txt)

++ cat xyz.txt
+ ./script.sh --params c=3 d=4

This behaviour is not present if the values in the file do not contain an equals sign. E.g.

e-5
f-6

... 
+-zsh:20> ./script.sh --params e-5 f-6

I tried disabling as many setopt as I could without success.

How can I prevent Zsh from enclosing my arguments in single quotes when they contain equal sign (mimic Bash behaviour)?