Find the answer to your Linux question:
Results 1 to 6 of 6
Hi All, i written a small shell script the usese export command... but when i execute that script, my shell will exit??? Please find the code temp.sh echo the value ...
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    49

    How to use export in shell???

    Hi All,

    i written a small shell script the usese export command... but when i execute that script, my shell will exit???
    Please find the code
    temp.sh

    echo the value exported by the shell is $var
    var=newvalue
    export var

    #exec otherfilepathname

    exec /home/abc.sh


    abc.sh contains

    echo "the value of $var"


    when i execute temp.sh, my shell terminal will exit....

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Don't use exec. Use "." or "sh" instead.

  3. #3
    Just Joined!
    Join Date
    Aug 2008
    Posts
    49

    Why not exec, what is the problem in using exec???

    Hey hi,

    I used .(dot), instead exec its working now... but what is the problem with exec???

  4. #4
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    "Exec" replaces the current shell with another program. It does not return.

  5. #5
    Just Joined!
    Join Date
    Aug 2008
    Posts
    49
    Cool man... but once its exit the terminal. i reopened the new terminal, but at that time i am not able to print that variable, which i jave exported...what is reason for that??? do need to put it in .bashrc???

  6. #6
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    The export statement only affects the current session. If you want to have the variable available in all your sessions, you need to put the export statement in an init file, such as ".bashrc".

Posting Permissions

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