Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Script interpreting a command strangely



On 2009-01-11 at 20:09 -0800, Webb Sprague wrote:
> #!/usr/bin/env zsh
> PGOPT=' -q -A -t -U mkn_f -h xxx.yyy.pdx.edu zzz' # command for DB
> PG="psql $PGOPT "
> psql $PGOPT
> $PG
> echo psql $PGOPT

zsh is not sh (by default) and does not split scalar variables on
whitespace, as POSIX sh does.

You can use arrays, or use "emulate sh", or "setopt SH_WORD_SPLIT".

Or you can word-split on a given variable expansion by prefixing the
name with '=' which is equivalent to SH_WORD_SPLIT being on for just
that one expansion.

...% zsh -f
redoubt% foo='echo bar'
redoubt% $foo
zsh: command not found: echo bar
redoubt% $=foo
bar
redoubt%

See zshoptions and zshexpn man-pages.

Regards,
-Phil



Messages sorted by: Reverse Date, Date, Thread, Author