Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting environment variables in tcsh

Status
Not open for further replies.

Muskaan

Programmer
Oct 21, 2002
47
US
Hi all,

Has anyone worked on tcsh ? I wanted to know how one can export environment variables from child to parent. I tried using setenv but the value remains only in the child shell script. It becomes "undefined" when I try to echo its value from the parent terminal session. anyone knows ????

Thanks in advance!
Muskaan
 
you can't [in any shell] - child's vars cannot be propagated up to its parent.

Unless you make your 'child' run in the same process as its parent [no pun intended]. For csh-like shells [incliding tcsh] look into 'source'.


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 

No, what I mean is to be able to export value from a shell script, say set_user_name.sh to the session that ran it, like so;

---snip---
[dhcp80:~/verify_ut] muskaan% echo $SHELL
/bin/tcsh

[dhcp80:~/verify_ut] muskaan% cat set_user_name.sh
#!/bin/tcsh
setenv user_name muskaan
echo user_name is $user_name

[dhcp80:~/verify_ut] muskaan% ./set_user_name.sh
user_name is muskaan

[dhcp80:~/verify_ut] muskaan% echo $user_name
user_name: Undefined variable.
---snip---

So although when I run set_user_name.sh, the value of user_name is properly set as &quot;muskaan&quot;, it is an undefined variable when I try to see the value from the command prompt.

I am trying to determine an equivalent of &quot;export&quot; as in ksh. In which, I can export a variable within a file, and run the file in the same shell, like &quot;. <filename>&quot; (dot space filename). so after the file is run, the varible exported retains a value. Why can't i do this in tcsh ? :(

Thanks for your time!
Muskaan


 
As I said........

source ./set_user_name.sh

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
duh, I did not understand that point earlier, thanks tonnes!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top