export variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting export variables
# 1  
Old 07-02-2004
export variables

I have a master shell, which calls another shell to export some env variables. But when I just run the child shell from the command line, and see if the variables are exported by doing,

echo $EXPORTED_VAR1

I am not seeing the value.

But I am sure, I am using the child shell from a master shell which is running successfully daily.

What am I missing here. Purpose of my test is, I just added few more variables to be exported in the same script, just want to make sure if they are being exported OK.

Thx,

srishan
# 2  
Old 07-02-2004
The master script exports variables. Then script it runs will see the new environment. But when the master script exits, its environment goes away. Now you're back to the original environment. A child process cannot affect the environment of its parent.
# 3  
Old 07-03-2004
Question

It is exactly the other way round.

Like I said in the first posting, Child is setting the env variables, Master calls child script to set up the env variables, which are then used by the master script through out. As per your explanation, once the child process finishes, the environment is gone, which does not seem right, as they are visible in the master script.

I do not know if I am explaining it right.

My doubt is, when I test it like the following, it does not show me any results.

Unix Prompt:> ksh child_process.ksh -- supposed to set the env
Unix Prompt:> echo $VAR1

-- Result is NULL here, although that variable has been set and exported in the child_process.ksh, why?

When the same script is executed from Master script, $VAR1 is available with it's value.

I am just trying to understand, how this exporting mechanism is working. Hope it is clear now.

Thx,

srishan
# 4  
Old 07-03-2004
You are not seeing the environment variables because things really do work the way I said they do. Your login shell spawns a ksh process which executes youe script. This does change the environment of the ksh process. But it has no effect at all on the ebvironment of the login shell. Then the ksh process exits. Now you're back to the unchanged environment of the login shell.

Somewhere you've made an error if you think otherwise. The most probable explanation is that "I have a master shell, which calls another shell to export some env variables" is wrong. ksh has a concept of a "dotted script". If a script is invoked like this:
. /path/to/script
it works differently. Rather than invoking a new shell, the current shell just switches its own input to the script and starts processing. When it hits end of file, it continues after the dotted command. Since no child process was spawned, the current shell can change its own environment. This is my guess as to what's happening.
# 5  
Old 07-06-2004
Computer

That is exactly what is going on.

The point that I was missing was the shell invokation,
. /child_shell vs /child_shell

Thanks,

srishan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array - Export/Import in global environment variables.

Hello. During startup /etc/bash.bashrc.local generates some array ..... source /.../.../system_common_general_array_env_var ..... The file system_common_general_array_env_var contains : LEAP_VERSION='42.3' ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss' ... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

Export variables to subshells

So i have a script that is like this: #!/bin/sh VARA="elementary 1 elementary 2 nursery A nursery B highschool AZ" echo "${ContentOfADifferentSCRIPT}" | sh i do not have control over the script that is inside the variable "${ContentOfADifferentSCRIPT}". however, i know that the... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

Read variables from a file and then export it.

Hi I want to read variables from one file and then set it as environment variable; The text file is test.txt which contains SPEED:1000 IP:172.26.126.11 My code is: while read line; do var1=`echo $line | awk 'BEGIN {FS=":"} { print $1 }'` echo $var1 var2=`echo $line | awk 'BEGIN {FS=":"}... (8 Replies)
Discussion started by: SSM
8 Replies

4. Shell Programming and Scripting

Columns Built in awk Variables don't export

I need to export the built in awk variables for columns so that they are available for the rest of the script. This is what I have so far: cat /tmp/test | eval `awk '{print "export NAME="$1; print "export NAME2="$2;}'` echo Host is "$NAME" and Host2 is "$NAME2" When I run bash -x to... (2 Replies)
Discussion started by: newbie2010
2 Replies

5. UNIX for Advanced & Expert Users

Bash script with export variables

Hi all guys, how you can read in thread title, I'm deploying a bash script in which I have to export some variables inside it. But (I think you know) the export command works only inside the script and so, on exit command, the variables aren't set like I set inside the script. Consequently in... (8 Replies)
Discussion started by: idro
8 Replies

6. UNIX for Advanced & Expert Users

How to export ENV variables, which remains set for all the shell

Hi ! How to export ENV variables, which remains set for all the shell Example :- Login :myID Pwd : **** -> Here my ID .profile is executed. Let say I set MYENV variable Kisses% rlogin ABC -l XXXGroupID -> I login into a remote Solaris Server ABC password : **** -> "XXXGroupID's... (1 Reply)
Discussion started by: dashok.83
1 Replies

7. Solaris

not able to export the Variables

I am working with Sun Solaris 9 and I want to export the environment variable from my application(xxxx.ksh) but I am not able to see it when I am using SET command I am writing some variables which I have to set COMMON_USER_HOME=${HOME} export COMMON_USER_HOME echo... (6 Replies)
Discussion started by: smartgupta
6 Replies

8. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

9. Shell Programming and Scripting

script to export variables

Hi, I am a newbie to unix as well as scripting. I need to write a script, which on execution sets the necessay oracle variables. Can someone help me out as to how to proceed? also can u suggest good tutorial for bash/shell scripting? thanks (1 Reply)
Discussion started by: aboxilica
1 Replies

10. Shell Programming and Scripting

export env variables

hi i want to write a shell script to set environment variables . But i am not been able to set that for the current shell instead i have to spawn a new shell. Is there a way to set the env variable for the current shell using shell script in bash shell ? Thnx (2 Replies)
Discussion started by: varun.81
2 Replies
Login or Register to Ask a Question