Explaination on export command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Explaination on export command
# 1  
Old 12-18-2014
Linux Explaination on export command

Hello Team,

Could you pls explain how export command works in below code:

Code:
for i in ${!SDV_*}; do
        export $i
    done

As per my understanding, if
Code:
SDV_1=test1;SDV_2=test2;test1=var1;test2=var2

then in for loop below export will get executed.
Code:
export var1;export var2

But, Will this actually work like normal export command below?
Code:
export SDV_1=test1;
export test1=var1

Could you explain and correct me if wrong.

also i tried below and did not get the values in the new sessions.

On Same session:
Code:
$ var1=test1;
$ export var1;
$ echo $var1
test1
$ export var2;
$ var2=test2;
$ echo $var2
test2
$

On new session:
Code:
$ echo $var1

$ echo $var2

$

Regards,
Chandana

Last edited by chandana.hs; 12-18-2014 at 01:39 AM.. Reason: had missed a line of code
# 2  
Old 12-18-2014
Hello chandana,

Welcome to forums. If you want to add a variable's value permanently then you can add it in your .profile and then it will work for new sessions also.
Let me give you an example here.

Let's say we want to set prompt sign for a specific user then we can add it in .profile as follows.
Code:
export PS1="${LOGNAME}@$(hostname)$ "

Also following link may help you in same to understand it better.
https://in.answers.yahoo.com/questio...8140017AAo0wb2


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 12-18-2014
Thanks Ravinder. Smilie

Could you/Team explain on how the for loop is working in below code block?

Code:
for i in ${!SDV_*}; do         export $i     done

Regards,
Chandana

---------- Post updated at 02:59 PM ---------- Previous update was at 01:10 PM ----------

Thanks.

Yes, it seems i understand now.

Export helps to define a variable for the current and in its child sessions.

But we have to define/add it to bash_rc file for permanent for all the sessions(child or totally a fresh session).

Correct me if wrong.

Regards,
Chandana
# 4  
Old 12-18-2014
Code:
export $i

will export the i variable, which you then overwrite several times in your loop.
Children do not necessarily run bashrc when created, so you may need to take extra action to have those variables available.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Explaination on if true

Hi Team, I need to know why ppl use If true loop instead of just writing down the sequence of code lines. 1: echo "Line1" if true; then echo "Line2" fi echo "Line3" 2: echo "Line1" echo "Line2" echo "Line3" Could you explain what does the if true loop make difference in 1st compare... (3 Replies)
Discussion started by: chandana hs
3 Replies

2. Shell Programming and Scripting

Explaination on Behavior of awk command

Hello Admin, Could you pls explain on the below behavior of the awk command. $ awk -F">20" "/Cyclomatic complexity/ && /;add;/{print \$1}" inspect_64d_369980 | awk '{print $NF}' | sort | tail -1 65 $var=`awk -F">20" "/Cyclomatic complexity/ && /;add;/{print \$1}" inspect_64d_369980 | awk... (3 Replies)
Discussion started by: chandana hs
3 Replies

3. Programming

Need explaination for a function please

can anybody explain a long fpathconf(int fildes, int name); what it do like 1- lim = fpathconf(STDIN_FILENO, _PC_NAME_MAX); printf("%s %ld\n", "_PC_NAME_MAX: ", lim); 2- lim = fpathconf(STDIN_FILENO, _PC_PATH_MAX); printf("%s %ld\n", " _PC_PATH_MAX ", lim); 3- lim =... (1 Reply)
Discussion started by: fwrlfo
1 Replies

4. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

5. Shell Programming and Scripting

Looking for awk code explaination

{ # print NF,NR,$0; if ( ($(NF-1) != 0) && ($NF != 0) ) {if ($(NF-1) > $NF) {percent=$(NF-1)/$NF-1;} else {percent=$NF/$(NF-1)-1;} } printf "%8.4f\%\n",percent*100; if (percent > 0.05||percent < -0.05 ){exit 1;} }' Use code tags please, ty. Also try to use a more... (1 Reply)
Discussion started by: bosmat shani
1 Replies

6. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

7. UNIX for Advanced & Expert Users

Export command

Hi all, Want to know what does export command do?? What is its functionality? And on a shell prompt $at=1 $ echo $at 1 The variable above is it available to other script??? (3 Replies)
Discussion started by: prakash.kudreka
3 Replies

8. Linux

I would like to know the explaination.

Hi, I'm new to LINUX Scripting, I would like to know the full explaination of the below scripts. thank you. 1st script #! /bin/sh . /opt/home/hssadmin/cindy/formatxml.env `testrecord.scp` `testEXGU.scp` 2nd Script #! /bin/sh . /opt/home/hssadmin/cindy/formatxml.env cd... (1 Reply)
Discussion started by: AudreyEliza
1 Replies

9. UNIX for Dummies Questions & Answers

export command

Is there any difference between these 2 commands :- export var="a" and var="a" export var (2 Replies)
Discussion started by: radhika03
2 Replies
Login or Register to Ask a Question