Because splitting and variable interpolation and de-quoting happens at the same time - and so any quotes within a variable are meaningless.
For example:
% ls "a b" "c d"
ls: a b: No such file or directory
ls: c d: No such file or directory
The parameters to ls
are:
ls
a b
c d
Where as:
% v='ls "a b" "c d"'
% echo $v
ls "a b" "c d"
% $v
ls: "a: No such file or directory
ls: "c: No such file or directory
ls: b": No such file or directory
ls: d": No such file or directory
Not what you want.
You can use eval
:
% eval $v
ls: a b: No such file or directory
ls: c d: No such file or directory
But honestly, I don’t really understand what eval
does so I don’t know why it works.
See: I'm trying to put a command in a variable, but the complex cases always fail!.