help-bash
[Top][All Lists]
Advanced

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

[Help-bash] break and continue inside subshells


From: Glenn Morris
Subject: [Help-bash] break and continue inside subshells
Date: Thu, 18 Oct 2012 16:12:53 -0700
User-agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)

Hi,

I found this behaviour a little odd (bash 4.2.37 on RHEL6):

## This is fine:
( echo 1; break; echo 2 )

  -> Prints "1", bash: break: only meaningful in a `for', `while', or
  `until' loop, "2"

So a "break" inside a subshell has no effect (as expected).


## This is suprising:
for f in 1 2; do
  (
    echo $f
    break
    echo X
  )
  echo Y
done

It prints "1", "Y", "2", "Y".
So now the break does have an effect, but not the expected one. It just
jumps to the end of the subshell, not the next loop iteration. ksh and
zsh seem to behave in the same way, but it seems odd to me...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]