0
Thanks

A few words of thanks would be greatly appreciated.

Export command in shell script?



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.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
Related
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).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!