The following works in my shell (zsh):
> FOO='ls'
> $FOO
file1 file2
but the following doesn't:
> FOO='emacs -nw'
> $FOO
zsh: command not found: emacs -nw
even though invoking emacs -nw
directly opens Emacs perfectly well.
Why?
Because there's no command called To store commands, you generally use functions:
To store several arguments, you generally use arrays:
To store a string containing several words separated by spaces and have it split on spaces, you can do:
You could rely on word splitting performed on IFS (IFS contains space, tab, newline and nul by default):
|
|||||||||||||||||
|
For future readers it should be mentioned that the "standard" way of doing such thing is to
One can also evaluate expression with command substitution:
These methods works fine at least in |
|||
|
zsh
behaves as you'd expect. When you type$cmd
, it runs the command whose name is stored in$cmd
.bash
(and most other Bourne like shells) invoke the split+glob operator on unquoted variables,zsh
fixed that. – Stéphane Chazelas Dec 28 '14 at 20:59