Export command in shell script?

December 2016



Issue


Suppose in a program a line is there:

XYZ='/home/abc/pqr/' 
;;;;;;etc 


and then
what will happen if i write a command:
export XYZ 

Solution


The issue is that scripts run in a private subshell, and therefore don't affect the shell that called them.

If we pretend that we have a script like this:
Code:


#!/bin/bash 
# Name: test_script 

export OOGA=echo 'ooga' 
export BOOGA=echo 'booga' 


Then we can add it to the current shell by using the source command:
Code:


source test_script

Note


Thanks to kupendra for this tip on the forum.

Related :

This document entitled « Export command in shell script? » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.