[Top][All Lists]

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

Re: bash leaves all for loop constructs when assignment w. expression fa

From: Chet Ramey
Subject: Re: bash leaves all for loop constructs when assignment w. expression fails
Date: Fri, 25 Apr 2008 13:12:44 -0400
User-agent: Thunderbird (Macintosh/20080213)

address@hidden wrote:
Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2
uname output: Linux lion 2.6.18-5-686 #1 SMP Mon Dec 24 16:41:07 UTC 2007 i686 
Machine Type: i486-pc-linux-gnu

Bash Version: 3.1
Patch Level: 17
Release Status: release

    If you have an assignment with a wrong expression, e.g. VAR=$[8#9] bash
    displays an error message and the script runs on. But if this error
    is inside a for loop - or two nested for loops - bash leaves all loops
    at once and goes to the next statement after all loops. I would expect
    bash to continue with the next statement in the loop. Or at least abandon
    the script. I do not have a problem with the error itself but with the
    handling of it in the bash.

Your analysis is correct.  When bash encounters a variable assignment
error, it abandons execution of all "enclosing" commands, which includes
loops and shell functions, back to the top-level shell context.

At that point, bash decides whether or not to abandon execution entirely.
Shells running in Posix mode exit the shell script; shells not in Posix
mode do not.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                       Live Strong.  No day but today.
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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