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

if [[ $line_write > " " && $line_write == "R" ]]
  echo "Exporting"
  export FLAG=Y
  #export $FLAG;
elif [[  $line_write > " " && $line_write== "N" ]]
  export FLAG=N


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

 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.