The following works in my shell (zsh):> FOO='ls'> $FOOfile1 file2but the following doesn't:> FOO='emacs -nw'> $FOOzsh: command not found: emacs -nweven though invoking emacs -nw directly opens Emacs perfectly well. Why?
Running commands stored in shell variables
shell;zsh;quoting;variable
Because there's no command called emacs -nw. There's a command called emacs to which you can pass a -nw option.To store commands, you generally use functions:foo() emacs -nw $@foo ...To store several arguments, you generally use arrays:foo=(emacs -nw)$foo ...To store a string containing several words separated by spaces and have it split on spaces, you can do:foo='emacs -nw'${(s: :)foo} ...You could rely on word splitting performed on IFS (IFS contains space, tab, newline and nul by default):foo='emacs -nw'$=foo ...