Austin Group Bug Tracker
2014-06-02 05:55:13 UTC
The following issue has been SUBMITTED.
======================================================================
http://austingroupbugs.net/view.php?id=842
======================================================================
Reported By: rhansen
Assigned To:
======================================================================
Project: 1003.1(2013)/Issue7+TC1
Issue ID: 842
Category: Shell and Utilities
Type: Omission
Severity: Objection
Priority: normal
Status: New
Name: Richard Hansen
Organization: BBN
User Reference:
Section: XCU 2.14 break, continue
Page Number: 2358, 2362
Line Number: 75117-75121, 75244-75250
Interp Status: ---
Final Accepted Text:
======================================================================
Date Submitted: 2014-06-02 05:55 UTC
Last Modified: 2014-06-02 05:55 UTC
======================================================================
Summary: meaning of "enclosing loop" with break/continue
unclear
Description:
The results of running 'break' and 'continue' are specified in terms of the
enclosing for, while, or until loop(s). However, it is unclear what
"enclosing" means. For example, how should the following script behave:
foo() {
for i in 1 2; do
echo " running bar ($i)..."
bar
echo " bar returned $?"
done
}
bar() {
for j in 1 2; do
do_break() {
echo " breaking..."
false
break 2
echo " break returned $?"
}
echo " running do_break ($j)..."
do_break
echo " do_break returned $?"
done
}
echo "running foo..."
foo
echo "foo returned $?"
Should the 'break' command do nothing because it is not a command in a
compound list associated with a loop? Should it only break out of the
inner loop because it is syntactically "inside" the inner loop but not the
outer loop? Should it break out of the outer loop because both loops were
executing at the time break was run?
One could interpret "enclosing" as implying lexical/static scope: a
break/continue command must be one of the commands in the compound list
associated with the loop in order for the loop to qualify as enclosing the
command.
Alternatively, one could interpret "enclosing" as implying dynamic scope:
A break/continue command is enclosed by a loop if the loop is executing
when the command is executed.
The following is a list of how the 'break' in the above script behaves in
some existing implementations:
* bash (POSIX mode), zsh (sh emulation mode), dash, and NetBSD's
/bin/sh: breaks out of the outer loop
* ksh93: does nothing (no error message, exit status is 0)
* mksh: prints an error message but otherwise does nothing (exit
status is 0)
Scripts sourced with the dot command lead to similar questions. Here's an
example script:
cat <<\EOF >/tmp/foo
for i in 1 2; do
echo " running bar ($i)..."
. /tmp/bar
echo " bar returned $?"
done
EOF
cat <<\EOF >/tmp/bar
for j in 1 2; do
echo " running do_break ($j)..."
. /tmp/do_break
echo " do_break returned $?"
done
EOF
cat <<\EOF >/tmp/do_break
echo " breaking..."
false
break 2
echo " break returned $?"
EOF
echo "running foo..."
. /tmp/foo
echo "foo returned $?"
With the above script, the 'break' behaves as follows:
* ksh93, bash (POSIX mode) and now NetBSD's /bin/sh [1]: breaks out
of the outer loop
* zsh (sh emulation mode): errors out
* dash: acts like 'return 0'
* mksh: prints an error message but otherwise does nothing (exit
status is 0)
[1] http://thread.gmane.org/gmane.os.netbsd.bugs/70663
Also, the behavior when break or continue is run outside of a loop is
unclear. The specification for break without arguments says "shall exit
from the smallest enclosing [...] loop, if any", but then goes on to talk
about breaking out of the outermost enclosing loop (because the default is
equivalent to n=1, and 1 is greater than the number of enclosing loops).
The specification for continue doesn't have the "if any" qualifier.
Desired Action:
(I will post proposed wording changes as a bug note later. Given the
implementation diversity, I'm guessing we'll want to go with "unspecified"
for Issue 7 TC2. For Issue 8, I don't know if lexical or dynamic scope is
preferred.)
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2014-06-02 05:55 rhansen New Issue
2014-06-02 05:55 rhansen Name => Richard Hansen
2014-06-02 05:55 rhansen Organization => BBN
2014-06-02 05:55 rhansen Section => XCU 2.14 break,
continue
2014-06-02 05:55 rhansen Page Number => 2358, 2362
2014-06-02 05:55 rhansen Line Number => 75117-75121,
75244-75250
======================================================================
======================================================================
http://austingroupbugs.net/view.php?id=842
======================================================================
Reported By: rhansen
Assigned To:
======================================================================
Project: 1003.1(2013)/Issue7+TC1
Issue ID: 842
Category: Shell and Utilities
Type: Omission
Severity: Objection
Priority: normal
Status: New
Name: Richard Hansen
Organization: BBN
User Reference:
Section: XCU 2.14 break, continue
Page Number: 2358, 2362
Line Number: 75117-75121, 75244-75250
Interp Status: ---
Final Accepted Text:
======================================================================
Date Submitted: 2014-06-02 05:55 UTC
Last Modified: 2014-06-02 05:55 UTC
======================================================================
Summary: meaning of "enclosing loop" with break/continue
unclear
Description:
The results of running 'break' and 'continue' are specified in terms of the
enclosing for, while, or until loop(s). However, it is unclear what
"enclosing" means. For example, how should the following script behave:
foo() {
for i in 1 2; do
echo " running bar ($i)..."
bar
echo " bar returned $?"
done
}
bar() {
for j in 1 2; do
do_break() {
echo " breaking..."
false
break 2
echo " break returned $?"
}
echo " running do_break ($j)..."
do_break
echo " do_break returned $?"
done
}
echo "running foo..."
foo
echo "foo returned $?"
Should the 'break' command do nothing because it is not a command in a
compound list associated with a loop? Should it only break out of the
inner loop because it is syntactically "inside" the inner loop but not the
outer loop? Should it break out of the outer loop because both loops were
executing at the time break was run?
One could interpret "enclosing" as implying lexical/static scope: a
break/continue command must be one of the commands in the compound list
associated with the loop in order for the loop to qualify as enclosing the
command.
Alternatively, one could interpret "enclosing" as implying dynamic scope:
A break/continue command is enclosed by a loop if the loop is executing
when the command is executed.
The following is a list of how the 'break' in the above script behaves in
some existing implementations:
* bash (POSIX mode), zsh (sh emulation mode), dash, and NetBSD's
/bin/sh: breaks out of the outer loop
* ksh93: does nothing (no error message, exit status is 0)
* mksh: prints an error message but otherwise does nothing (exit
status is 0)
Scripts sourced with the dot command lead to similar questions. Here's an
example script:
cat <<\EOF >/tmp/foo
for i in 1 2; do
echo " running bar ($i)..."
. /tmp/bar
echo " bar returned $?"
done
EOF
cat <<\EOF >/tmp/bar
for j in 1 2; do
echo " running do_break ($j)..."
. /tmp/do_break
echo " do_break returned $?"
done
EOF
cat <<\EOF >/tmp/do_break
echo " breaking..."
false
break 2
echo " break returned $?"
EOF
echo "running foo..."
. /tmp/foo
echo "foo returned $?"
With the above script, the 'break' behaves as follows:
* ksh93, bash (POSIX mode) and now NetBSD's /bin/sh [1]: breaks out
of the outer loop
* zsh (sh emulation mode): errors out
* dash: acts like 'return 0'
* mksh: prints an error message but otherwise does nothing (exit
status is 0)
[1] http://thread.gmane.org/gmane.os.netbsd.bugs/70663
Also, the behavior when break or continue is run outside of a loop is
unclear. The specification for break without arguments says "shall exit
from the smallest enclosing [...] loop, if any", but then goes on to talk
about breaking out of the outermost enclosing loop (because the default is
equivalent to n=1, and 1 is greater than the number of enclosing loops).
The specification for continue doesn't have the "if any" qualifier.
Desired Action:
(I will post proposed wording changes as a bug note later. Given the
implementation diversity, I'm guessing we'll want to go with "unspecified"
for Issue 7 TC2. For Issue 8, I don't know if lexical or dynamic scope is
preferred.)
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2014-06-02 05:55 rhansen New Issue
2014-06-02 05:55 rhansen Name => Richard Hansen
2014-06-02 05:55 rhansen Organization => BBN
2014-06-02 05:55 rhansen Section => XCU 2.14 break,
continue
2014-06-02 05:55 rhansen Page Number => 2358, 2362
2014-06-02 05:55 rhansen Line Number => 75117-75121,
75244-75250
======================================================================