Re: 'continue' does not work in files sourced with dotcmd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/06/2011 09:37 PM, Herbert Xu wrote:
> On Sat, Feb 26, 2011 at 06:23:54PM +0000, Taylan Ulrich B. wrote:
>> Using latest dash from git.
>> Transcript:
>>
>> $ echo continue > foo
>> $ for i in 1; do . ./foo; echo foobar; done
>> foobar
>> $
> 
> While this does look inconsistent, this behaviour is not confined
> to dash.  pdksh also does the same thing.

I've asked on the Austin Group whether this is a hole in POSIX, since
the standard appears to be silent on whether a for loop around a dot
script is visible to commands within the dot script.

> 
> So I'm not particularly keen on changing this.

Unfortunately, I argue that dash DOES have a bug.  Compare the zsh behavior:

$ zsh -c 'emulate sh; printf "continue\\necho \$?" > f; for i in 1; do .
./f; echo "$? hi"; done; rm f'
./f:continue:1: not in while, until, select, or repeat loop
1 hi

zsh rejected the continue statement (no containing loop within the
current scoping of the dot script), and as a result also aborted the
overall dot script - but in doing so, it properly emitted an error message.

Unless the Austin Group rules otherwise, I'm okay with dash rejecting
the continue command and aborting the dot script - but only on the
condition that the error is diagnosed, rather than silently papered
over.  But it may be worth waiting for the Austin Group ruling, to see
if the bash/ksh behavior of continuing on to the loop that is enclosing
the dot script is required, or merely one possible alternative, before
changing dash behavior (that is, no point wiring up an error message
unless we know that issuing an error message complies with the standard).

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux