* EXEC peculiarities
@ 2004-08-15 15:14 Jay Guerette
2004-08-15 16:16 ` Georg Neis
0 siblings, 1 reply; 5+ messages in thread
From: Jay Guerette @ 2004-08-15 15:14 UTC (permalink / raw)
To: zsh-users
I am a recent convert from Bash, and I'm confused about the behavior of
the 'exec' builtin. (zsh 4.2.0 on Linux)
#! /bin/bash
EXEC='/sbin/ifconfig eth0'
exec $EXEC
returns the expected output; the configuration of eth0
#! /bin/zsh
EXEC='/sbin/ifconfig eth0'
exec $EXEC
returns: "no such file or directory: /sbin/ifconfig eth0"
#! /bin/zsh
EXEC='/sbin/ifconfig'
ARGS='eth0'
exec $EXEC $ARGS
however, again works as expected
Am I doing something wrong? Why does the 2nd example fail?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EXEC peculiarities
2004-08-15 15:14 EXEC peculiarities Jay Guerette
@ 2004-08-15 16:16 ` Georg Neis
2004-08-15 17:24 ` Jay Guerette
0 siblings, 1 reply; 5+ messages in thread
From: Georg Neis @ 2004-08-15 16:16 UTC (permalink / raw)
To: zsh-users
* Jay Guerette <JayGuerette@pobox.com> wrote:
> I am a recent convert from Bash, and I'm confused about the behavior of
> the 'exec' builtin. (zsh 4.2.0 on Linux)
>
> #! /bin/bash
> EXEC='/sbin/ifconfig eth0'
> exec $EXEC
>
> returns the expected output; the configuration of eth0
>
> #! /bin/zsh
> EXEC='/sbin/ifconfig eth0'
> exec $EXEC
>
> returns: "no such file or directory: /sbin/ifconfig eth0"
>
> #! /bin/zsh
> EXEC='/sbin/ifconfig'
> ARGS='eth0'
> exec $EXEC $ARGS
>
> however, again works as expected
The exec builtin has nothing to do with this.
http://zsh.sunsite.dk/FAQ/zshfaq03.html#l17
Georg
--
Tomorrow will be cancelled due to lack of interest.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EXEC peculiarities
2004-08-15 16:16 ` Georg Neis
@ 2004-08-15 17:24 ` Jay Guerette
2004-08-15 18:02 ` Wayne Davison
0 siblings, 1 reply; 5+ messages in thread
From: Jay Guerette @ 2004-08-15 17:24 UTC (permalink / raw)
To: zsh-users
>> I am a recent convert from Bash, and I'm confused about the behavior of
>> the 'exec' builtin. (zsh 4.2.0 on Linux)
>>
>> #! /bin/bash
>> EXEC='/sbin/ifconfig eth0'
>> exec $EXEC
>>
>> returns the expected output; the configuration of eth0
>>
>> #! /bin/zsh
>> EXEC='/sbin/ifconfig eth0'
>> exec $EXEC
>>
>> returns: "no such file or directory: /sbin/ifconfig eth0"
>
> The exec builtin has nothing to do with this.
>
> http://zsh.sunsite.dk/FAQ/zshfaq03.html#l17
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?
#! /bin/zsh
EXEC='/sbin/ifconfig eth0'
EXEC=(${(s: :)EXEC})
exec $EXEC
#! /bin/zsh
EXEC='/sbin/ifconfig eth0'
EXEC=(${=EXEC})
exec $EXEC
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EXEC peculiarities
2004-08-15 17:24 ` Jay Guerette
@ 2004-08-15 18:02 ` Wayne Davison
2004-08-15 19:12 ` Jay Guerette
0 siblings, 1 reply; 5+ messages in thread
From: Wayne Davison @ 2004-08-15 18:02 UTC (permalink / raw)
To: Jay Guerette; +Cc: zsh-users
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).
..wayne..
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EXEC peculiarities
2004-08-15 18:02 ` Wayne Davison
@ 2004-08-15 19:12 ` Jay Guerette
0 siblings, 0 replies; 5+ messages in thread
From: Jay Guerette @ 2004-08-15 19:12 UTC (permalink / raw)
To: zsh-users
> 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!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-08-15 19:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-15 15:14 EXEC peculiarities Jay Guerette
2004-08-15 16:16 ` Georg Neis
2004-08-15 17:24 ` Jay Guerette
2004-08-15 18:02 ` Wayne Davison
2004-08-15 19:12 ` Jay Guerette
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).