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

Re: strange bash behavior



On Mon, 02 Sep 2013 05:27:55 -0400 (EDT), Matej Kosik wrote:
> 
> This morning I have been puzzled by bash.
> After typing the following command:
> 
> 	for i in `seq 1 5`;do echo $i; test $i = 3 && break; done
> 
> I see:
> 
> 	1
> 	2
> 	3
> 
> Which is OK.
> 
> However, if the "break" command appears in a subshell:
> 
> 	for i in `seq 1 5`;do echo $i; test $i = 3 && (break); done
> 
> then the "break" command does not seem to have any effect
> 
> 	1
> 	2
> 	3
> 	4
> 	5
> 
> I am curious, is this something to be expected?

Interesting.  If "break" appears out of context, you should get
an error message something like:

   bash: break: only meaningful in a 'for', 'while', or 'until' loop

You didn't get an error message, so part of bash thinks it is in context.
Yet it did not exit the loop.  It seems to me that you should get one
behavior or the other.  Either you should get an error message or it
should exit the loop.

-- 
  .''`.     Stephen Powell    
 : :'  :
 `. `'`
   `-


Reply to: