0

I have the following script named run.sh:

#This is run.sh

prerequisite(){

config_file=./../config/config.sh
source $config_file

    echo "VAR1 inside prerequisite: $VAR1"
    echo "country currency inside prerequisite: $country_currency[@]"
}

LIST_OF_COUNTRIES=`cat country_list.txt`

transform() {
    local country="$@"
    prerequisite
    echo "VAR1 inside transform: $VAR1"
    echo "country currency inside transform: $country_currency[@]"
}

transform ${LIST_OF_COUNTRIES[@]} &
transformpid=$!

wait $transformpid

echo "Complete"

The content of my config.sh file is:

VAR1="value1"
declare -a country_currency=( "INR" "USD" "JPY" )

When I run my run.sh file, I get the following output:

VAR1 inside prerequisite: value1
country currency inside prerequisite: INR USD JPY

VAR1 inside transform: value1
country currency inside transform:

As I see from the output, the value of all the variables that I am sourcing from my config .sh file is getting fetching into the prerequisite function. Whereas the values in the array are not getting fetched into the transform function. This is just a small snippet of code. I am doing multiple calls to the prerequisite function to dynamically source the values in my actual code. What am I doing wrong over here? Isn't the scope of the variable and the array that I have declared, supposed to be the same?

3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.