I want to pass a variable which I set in a subscript to the parent script. I want to do that either as a function or just by "echo"ing the variable:
parent.sh
#!/bin/csh
enter code here
set VAR_2_CHILD_1 = myName
set VAR_2_CHILD_2 = MAIN_PATH/output.txt
$MAIN_PATH/child.sh $VAR_2_CHILD_1 $VAR_2_CHILD_2
child.sh
#!/bin/csh
if ($1 =~ *something*) then
set NAME_SL = False
set SUBDIRID = True
echo $1 $SUBIDDIR >> $2
endif
echo $NAME_SL $SUBDIRID
or:
#!/bin/csh
function pass_var() {
if ($1 =~ *something*) then
set NAME_SL = False
set SUBDIRID = True
echo $1 $SUBIDDIR >> $2
endif
return $NAME_SL $SUBDIRID
}
In the later case I do not know how to call the function in the parent.sh
In general the subscript should choose between option according to $VAR_2_CHILD_1 and VAR_2_CHILD_2 and returning some string variable $NAME_SL and $SUBDIRID. I do not how to do that.
I also read other questions here like: Bash - Return value from subscript to parent script but I could not find anything which works for me.