bug-bash
[Top][All Lists]
Advanced

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

bash2 can't parse function definitions inside if statements


From: clgonsal
Subject: bash2 can't parse function definitions inside if statements
Date: Sat, 11 Nov 2000 13:35:21 -0800

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H  -D_FILE_OFFSET_BITS=64  -I.  
-I. -I./lib -I/usr/include -g -O2
uname output: Linux keeshah.penguinpowered.com 2.2.12 #4 Sun Sep 5 01:30:22 PDT 
1999 i586 unknown
Machine Type: i386-redhat-linux-gnu

Bash Version: 2.03
Patch Level: 8
Release Status: release

Description:
        bash2 doen't seem to be able to parse if statements that contain
        function definitions. Note that plain old bash doesn't have this
        problem. Here's a test script to demonstrate:

=========================== C U T   H E R E ===========================
# Test script for functions in ifs in bash2
# bash can execute this script just fine, but bash2 cannot :-(
#
# bash2 blows up on the else with an error like:
#
#    bash2-bug: line 36: syntax error near unexpected token `else'
#    bash2-bug: line 36: `else'
#
# if you remove the `else' and the two lines following it, bash2 still
# dies, but this time on the `fi'. It will also die in a similar fashion
# on an `elif'. It looks as though bash2 forgets that it's in an if
# statement once it hits the function definition.
#
# It seems that the problem is the function declaration.  It looks like
# bash2 doesn't like function declarations inside of an if statement.
# Moving the functions around within the if statement doesn't fix the
# problem. Removing them from the if statement does though.
#
# Since this script works fine in bash, you can test there for correct
# behaviour. Basically, it's supposed to output:
#
#    Ack!
#    goodbye world
#
# when passed no parameters, and
#
#    Howdy
#    hello world
#
# when passed more than zero parameters.

if [ -n "$*" ]
then
    function greet () { echo hello "$*" }
    echo Howdy
else
    function greet () { echo goodbye "$*" }
    echo Ack!
fi

greet world

=========================== C U T   H E R E ===========================

Repeat-By:
        Using the included test script, just type:
        
            bash2 testscript
        
        As far as I can tell, any function definition in an if statement
        fails in bash2.

-- 
  C. Laurence Gonsalves                "Any sufficiently advanced
  clgonsal@kami.com                     technology is indistinguishable
  http://cryogen.com/clgonsal/          from magic." -- Arthur C. Clarke



reply via email to

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