Exporting variable from one shell script to another script in bash [duplicate]

This question already has an answer here:

I am a newbie in Shell Scripting and i am trying to export a variable from child script to a parent script.below is the code and unfortunately its not working. not sure what is the issue. below is the code.

I have a script set-vars1.sh code is as below

#!/bin/bash
line_write="R"
FLAG=''
if [[ $line_write > " " && $line_write == "R" ]]
 then
  echo "Exporting"
  export FLAG=Y
  #export $FLAG;
elif [[  $line_write > " " && $line_write== "N" ]]
  then
  export FLAG=N
fi

EXIT_STATUS=-1
exit $EXIT_STATUS

I am trying to call this from set-vars2.sh the code is as below

#!/bin/bash
./set-vars1.sh
 echo $FLAG

When i try to run set-vars2.sh i am not able to echo the value of FLAG and its always blank.

Can you please let me know what is wrong here and how i can correct the same. been breaking my head a long time on this. so any help would be hugely helpful


Source: bash

Leave a Reply