Find the answer to your Linux question:
Results 1 to 4 of 4
Hi all, I am linux newbie. I just upgraded my linux box from SuSe-9.1 to SuSe-10.1 and all of suddenly I could not build my stuff. The problem I found ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    2

    exporting variables not working in SuSe-10.1

    Hi all,

    I am linux newbie. I just upgraded my linux box from SuSe-9.1 to SuSe-10.1 and all of suddenly I could not build my stuff. The problem I found is variables exported from one user shell cannot be picked up by another user shell. Basically I tried to wrote 2 scripts:
    -script1.sh:
    #!/bin/bash
    export HELLO="hello world!"
    sudo ./script2.sh
    #end script1.sh

    Here is the script2.sh
    #!/bin/bash
    echo $HELLO
    #end of script2.sh

    I ran ./script1.sh and HELLO was not echoed out, but I ran these scripts in another box with SuSe-9.1 "hello world" was printed out. Now I removed "sudo" in line 3 in script1.sh, "hello world" would be echoed out to the screen.

    Thanks for your help!

    -CP

  2. #2
    Linux Guru gogalthorp's Avatar
    Join Date
    Oct 2006
    Location
    West (by God) Virginia
    Posts
    3,105
    Shells live in their own environment they inherit from the process that created them. Environment changes only affect the current process they are not global. You need to use signals to communicate between process.

  3. #3
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,413
    gogalthorp, that's what I thought, but it looks like the script works when he removes the "sudo", which suggests that script2 can inherit the HELLO variable from script1. Also, he notes that it previously worked on a suse9.1 box.

    To be honest I don't understand why it worked at all (for the reasons you gave), but it seems like something else is going on here.
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

  4. #4
    Linux Guru gogalthorp's Avatar
    Join Date
    Oct 2006
    Location
    West (by God) Virginia
    Posts
    3,105
    If you run script one then script two in the same process, it will work. If you run script one then start a new process from process one then process two will inherit and script two will work. If you start a new process that does not inherit from process one script two will not work. I'm not sure that su inherits from the current process, I believe it inherits from the root process thus does not see changes in the environment set by process one running as user.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...