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)?
=
is also a special operator in the zsh syntax so needs quoted at least in some contexts (compareecho =ls
vsecho '=ls'
). Inbash
it's special as well in that it causes what follows to be subject to tilde expansion (at least when what's before looks like a valid variable name). You'll noticebash -xc 'echo +=~'
orbash -xc 'echo a=\~'
outputsecho 'a=~'
andecho '+=~'
(even if those quotes are not strictly necessary in that case).bash -xc 'a\=x'
outputsa=x
which is a bug though (asa=x
would assignx
toa
instead of running thea=x
command).zsh
's OK. – Stéphane Chazelas Oct 23 '20 at 17:24