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

Re: EXEC peculiarities

On Sun, Aug 15, 2004 at 01:24:56PM -0400, Jay Guerette wrote:
> Ok. So in the following examples, would the 1st form; ${(s: :)EXEC}; be
> preferred, since the documentation says using the 2nd form; ${=EXEC};
> forces SH_WORD_SPLIT on; potentially leading to unexpected behavior later?

${=VAR} only forces SH_WORD_SPLIT on for the duration of the variable's
expansion, so it's a good way to go when you need to use it.

However, I'd recommend just starting with an array in the first place,
when possible:

EXEC=(/sbin/ifconfig eth0)
exec $EXEC

The nice thing about this idiom is that it preserves args that have
spaces in them:

file1='this one.txt'
EXEC=(/bin/ls $file1 'that one.txt')
exec $EXEC

If you put that in a string and split it, it would not preserve the
multi-word args:

file1='this one.txt'
EXEC="/bin/ls $file1 that\\ one.txt"
exec ${=EXEC}

That would try to list "this", "one.txt", "that\", and "one.txt" (just
like bash would handle the string).


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