Exporting variable from one shell script to another script in bash -
this question has answer here:
- pass variables 1 shellscript another? 6 answers
i newbie in shell scripting , trying export variable child script parent script.below code , unfortunately not working. not sure issue. below code.
i have script set-vars1.sh code below
#!/bin/bash line_write="r" flag='' if [[ $line_write > " " && $line_write == "r" ]] echo "exporting" export flag=y #export $flag; elif [[ $line_write > " " && $line_write== "n" ]] export flag=n fi exit_status=-1 exit $exit_status i trying call set-vars2.sh code below
#!/bin/bash ./set-vars1.sh echo $flag when try run set-vars2.sh not able echo value of flag , blank.
can please let me know wrong here , how can correct same. been breaking head long time on this. hugely helpful
use source:
source ./set-vars1.sh or:
. ./set-vars1.sh #the first . intentional
Comments
Post a Comment