Re: Bug in bash? different from ksh, at any rate...



On Sat, May 28, 2011 at 01:14:42AM -0700, Rick Thomas wrote:

Can anybody explain this difference between the behavior of bash and
ksh?

When reading the man page, I would expect both of them to have the
behavior exhibited by ksh.
Why does bash seem to treat "return" like a single level "break" in
this context?

The "echo "$AA" | while read" is important context. If I change it
to "for i in 0 1", return does as expected.

If it's any help, changing "return" to "break 2" doesn't help. with
bash, it still gives "1 1 1 1"
while ksh still gives "1"

I wonder if it has anything to do with "while read" causing a
subshell to be created, and bash getting confused about the "return"
inside of a subshell. If so, it's a bug in bash that ksh gets
right, so it ought to be fixable.

I can't reproduce it:

$ cat strange.sh
function strange {
for j in 0 1 2 3
do
AA=' 1
2'
echo "$AA" | while read i
do
echo "$i"
return
done
done
}
echo $(strange)

$ bash ./strange.sh
1 1 1 1

$ ksh ./strange.sh
1 1 1 1

ii bash 4.1-3 The GNU Bourne Again SHell
ii mksh 39.3.20100725-1 MirBSD Korn Shell

--
Huella de clave primaria: AD8F BDC0 5A2C FD5F A179 60E7 F79B AB04 5299 EC56

Attachment: signature.asc
Description: Digital signature



Relevant Pages

  • Re: vi horizontal split screen
    ... I'm an old ksh hacker, but bash will do fine. ... I started on the SysV R2 Bourne shell, and used csh for a better ... Several ksh improvements were designed to make it faster and more efficient at processing scripts, and one way to do that was substitute built-ins for external commands called from the script. ...
    (comp.editors)
  • FAST, but full feature ksh.
    ... built ksh vs a statically built bash, I found that the ksh was ... sluggish bash to the POSSIBLY quicker ksh... ... case of molasses, try playing with shell scripting on cygwin, ... but today my measurement now isn't done ...
    (comp.unix.bsd.freebsd.misc)
  • Bug in bash? different from ksh, at any rate...
    ... I would expect both of them to have the behavior exhibited by ksh. ... Why does bash seem to treat "return" like a single level "break" in this context? ... The "echo "$AA" | while read" is important context. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Re: How to ensure consistency between two ksh process?
    ... I tested this with both bash and ksh. ... echo "$0 is running as PID $RunningPID" ...
    (comp.unix.shell)
  • Re: Environment bug in Bash?
    ... Thinking it might be because echo is ... I tried in in bash, ksh, and zsh, all with the same ... env foo=bar echo $foo ...
    (comp.unix.shell)