I have two scripts parent.sh and child.sh. There is a variable in parent.sh which needs to be accessed by the child process. I have achieved this by exporting the variable in the parent script and the variable is available to the child process?
Is there any way that child can modify the value of the export variable defined in parent shell?
Parent.sh
#!/bin/bash
export g_var=2
./child.sh
child.sh
#!/bin/bash
g_var=`expr $g_var + 1 ` #This modification is available in child shell only.
Most shells support the
sourcebuilt-in, which executes a script in the current shell rather than spawning a new one. In bash and a few others, the command.is equivalent tosource. I haven’t read it, but the POSIX shell standard might require the two to be equivalent. Try:“child.sh” is the same as your example.