Help in Setting Environment variables in TCSH | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Help in Setting Environment variables in TCSH

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-18-2008
kssandeep kssandeep is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 18 February 2008, 6:58 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Help in Setting Environment variables in TCSH

Hello All,

I am writing a script to set some environment variables which are required for a particular application. I understand that the environment variables set by Shell script can, at the max, be valid for the session. They will have to be set again once the session is closed and re-opened.

In my case, I can see that the environment variables are being set, but once the shell script execution completes, the environment variables are not set.

******************
#!/usr/bin/env tcsh
setenv SR_MGR_CONF_DIR /users/abc/tools

echo $SR_MGR_CONF_DIR


******************
I see the output of the echo is right... but if i execute the same echo command after the execution of the script, I am not able to see the environment variable.

Please let me know why is this so.

Thanks in advance
Regards
Sandeep
Sponsored Links
    #2  
Old 02-18-2008
agn agn is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 6 August 2013, 7:49 AM EDT
Posts: 345
Thanks: 0
Thanked 21 Times in 21 Posts
The shell script is sourced by a different shell, not the one you invoke it from. The shell exits when its done executing the shell script. So its a different session. Hence you won't be able to access the variables set in a shell script. So you'll need to set env variables in your shell from which you invoke the shell script. And you;ll be able to use the variabels in your shell script. Or you can set it in your .profile or .${SHELL}rc .
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Setting up environment variables exchequer598 UNIX for Dummies Questions & Answers 2 09-03-2010 12:10 AM
Setting Environment Variables bigubosu UNIX for Dummies Questions & Answers 4 04-30-2010 06:23 AM
Need help with setting up environment variables SSSB UNIX for Dummies Questions & Answers 1 01-21-2010 02:44 PM
Setting up Environment Variables rpandey Shell Programming and Scripting 6 06-06-2005 09:28 AM
setting environment variables ??? Gargamel UNIX for Dummies Questions & Answers 5 06-13-2002 11:12 AM



All times are GMT -4. The time now is 09:30 AM.