bug-bash
[Top][All Lists]
Advanced

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

Strange problem with source


From: Cecil Westerhof
Subject: Strange problem with source
Date: Sun, 12 Jan 2014 22:31:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Is this a known problem?

I have a strange problem with source. Sometimes variables are not
defined, but functions are.

I have a file a with:
    function includeFile() {
        local fileName
        local needsToExist=true

        if [[ ${1} == "--notNeeded" ]] ; then
            needsToExist=false; shift
        fi
        if [[ ${#} -ne 1 ]] ; then
            echo "includeFile [--notNeeded] <INPUT_FILE>"
            return 1
        fi
        INPUTFILE=${1}; shift

        if  [ -s ${INPUTFILE} -a -f ${INPUTFILE} -a -r ${INPUTFILE} ] ; then
            source ${INPUTFILE}
        else
            if [[ ${needsToExist} != false ]] ; then
                echo "${INPUTFILE} could not be used"
                return 1
            fi
        fi
    }

    includeFile b

In file b I have:
    declare testVariable="testing"
    echo ${testVariable}

    function testFunction {
        :
    }

When doing:
    source a

The string "testing" is printed and the function testFunction is
defined, but the variable testVariable is not defined.

When I change in file a the includeFile to source, testVariable is
defined.

Very strange indeed. Especially there includeFile does a source.

I am using bash 4.2.42(1)-release.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


reply via email to

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