Export command in shell script?

March 2017



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


Published by aakai1056.
This document, titled "Export command in shell script?," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).