Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: EXEC peculiarities
- X-seq: zsh-users 7853
- From: "Jay Guerette" <JayGuerette@xxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: EXEC peculiarities
- Date: Sun, 15 Aug 2004 15:12:57 -0400 (EDT)
- Importance: Normal
- In-reply-to: <20040815180215.GA25866@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <46981.217.160.254.91.1092582879.squirrel@xxxxxxxxxxxxxx> <912.411f8c59.a67bb@xxxxxxxxxxxxxxxxxxx> <48120.217.160.254.91.1092590696.squirrel@xxxxxxxxxxxxxx> <20040815180215.GA25866@xxxxxxxxx>
> 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:
>
> #!/bin/zsh
> EXEC=(/sbin/ifconfig eth0)
> exec $EXEC
>
> The nice thing about this idiom is that it preserves args that have
> spaces in them:
>
> #!/bin/zsh
> 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:
>
> #!/bin/zsh
> 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).
Ah. In my case, I'm pulling the target of 'exec' in from a variable, thus
the cause of this exercise. Subtleties noted. Many thanks!
Messages sorted by:
Reverse Date,
Date,
Thread,
Author