LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-13-2010, 10:08 AM   #1
deepti_114
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Rep: Reputation: 0
how to set environment variables that i use everyday permanently


Hi All,
I have bunch of environment variables that i have to set always for my work.Someone mentioned i can write a script to dp this and i googled it but haven't been successful so far and have to manually do them every time.
I have a tcsh shell.I read that i need to change the .login or .tcshrc files but havent been successful in finding these.Can someone please provide me some information i could use to do this?

Thanks

Deepti
 
Old 07-13-2010, 10:18 AM   #2
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Hi

What distro/version are you using?
 
Old 07-13-2010, 10:19 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi and welcome to LinuxQuestions!

Yes, you can put your own setenv statements either in $HOME/.login or in $HOME/.tcshrc. These are hidden files under your HOME directory: you can check if they already exist by means of:
Code:
ls -a $HOME/.tcshrc $HOME/.login
If not you can create them and add code at your pleasure. The file .tcshrc will be read by every shell upon starting a new shell session. The file .login will be read by every login shell after .tcshrc. See man tcsh (section FILES) for details.
 
Old 07-13-2010, 10:19 AM   #4
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by deepti_114 View Post
Hi All,
I have bunch of environment variables that i have to set always for my work.Someone mentioned i can write a script to dp this and i googled it but haven't been successful so far and have to manually do them every time.
I have a tcsh shell.I read that i need to change the .login or .tcshrc files but havent been successful in finding these.Can someone please provide me some information i could use to do this?

Thanks

Deepti
this should help you.

http://publib.boulder.ibm.com/infoce...bcug160325.htm
 
Old 07-13-2010, 10:22 AM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
in Bash you'd put them in ~/.bash_profile or /etc/profile for globally used ones.

Otherwise echo your setenv (or whatever applies to that shell) to a script and run the singular script. If you're in X, you could make it part of the terminal launch to run script and persist. Or use whatever ~/.??? applies to your preferred shell. Many means.
 
Old 07-13-2010, 10:56 AM   #6
deepti_114
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Original Poster
Rep: Reputation: 0
I have the Red Hat Enterprise Linux Client release 5.5 version.

I issued ls -a in my directory(/local/home/my_user_name) but the .cshrc and .login file do not exist so i created a login file and wrote all the env varaibles:


#script to se the env variables

setenv SPARE_PLUGIN /local/home/djain/SPARE/SPARE/
setenv SPARE_PREFIX $SPARE_PLUGIN/build/native/gcc-build/install/
setenv PATH /local/home/djain/gccbenchmarks/sesc/scripts/:$PATH
setenv BENCHDIR /local/home/djain/gccbenchmarks/benchmarks/
setenv SESCBUILDDIR /local/home/djain/gccbenchmarks/esesc-build
etc....

but when i logout and login again..the variables havent been set?
What am i messing here please?
 
Old 07-13-2010, 11:06 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by deepti_114 View Post
so i created a login file and wrote all the env varaibles
Which file did you create? Better to stick with $HOME/.tcshrc which should be read both by interactive and non-interactive shells. Also, please post the output of
Code:
echo $version
 
Old 07-13-2010, 11:09 AM   #8
deepti_114
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Original Poster
Rep: Reputation: 0
output of echo $version
tcsh 6.14.00 (Astron) 2005-03-25 (i386-intel-linux) options wide,nls,dl,al,kan,sm,rh,color,filec

i created a .login file

vim .login in /local/home/my_user_name
 
Old 07-13-2010, 11:17 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
What if you rename it to .tcshrc? Still the same problem?
 
Old 07-13-2010, 11:26 AM   #10
deepti_114
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Original Poster
Rep: Reputation: 0
yes it still does not work.
I even added #!bin/bash as the first line in the .tcshrc file..


deepti
 
Old 07-13-2010, 12:05 PM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by deepti_114 View Post
I even added #!bin/bash as the first line in the .tcshrc file.
Well.. nope. Since the login shell is /bin/tcsh and you use the setenv command it should give an error.

Anyway, it is a strange problem since the parsing (and sourcing) of the $HOME/.tcshrc file is hard-coded in the tcsh binary executable. Please, can you show us the actual content of $HOME/.tcshrc and the output of
Code:
ls -al $HOME/.tcshrc
? Thank you.
 
Old 07-14-2010, 10:02 AM   #12
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
A lot of the variables are inherited from the parent shell. So unless you completely logged out at the highest level, it might not be taking effect. Once set a reboot should apply it at the highest level, but you don't have to do that with linux. If you login at a console, and still need to set them manually, you might try setting them then su - (yourself). Then launch X or whatever environment suits. That should ensure inheritance to child processes.

Various shells have different syntax's for setting environment variables. set, setenv, export and other means in other shells. Make sure that you're using what's appropriate for your shell. While most have similar syntax's, they're not always interchangeable. According the tcsh's manpage printenv, setenv, unsetenv are the methods employed for it.

According to the man page for tcsh:

/etc/csh.cshrc
/etc/csh.login
~/.tcshrc
~/.cshrc
~/.history
~/.login
~/.cshdirs

are files of interest. With a whole lot of if this one isn't, then try here. Which implies, if this one IS here, then ignore that one. At a minimum any scripts in it should deploy a she bang of
!#/usr/bin/tcsh
or
!#/bin/tcsh
with or without /local/ depending on your distro and/or install method.

But I haven't actually used tcsh, so I could be wrong. Spelling correction at the cli seems intriguing though.
 
Old 07-16-2010, 09:37 AM   #13
deepti_114
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Original Poster
Rep: Reputation: 0
This is the exact content of my .tcshrc file:

#
#script to se the env variables

setenv SPARE_PLUGIN /local/home/djain/SPARE/SPARE/
setenv SPARE_PREFIX $SPARE_PLUGIN/build/native/gcc-build/install/
setenv PATH /local/home/djain/gccbenchmarks/sesc/scripts/:$PATH
setenv BENCHDIR /local/home/djain/gccbenchmarks/benchmarks/
setenv SESCBUILDDIR /local/home/djain/gccbenchmarks/esesc-build


According to my shell these commands seem appropriate yet they are not set when i login.
 
Old 07-16-2010, 10:19 AM   #14
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by deepti_114 View Post
According to my shell these commands seem appropriate yet they are not set when i login.
Yes, the syntax is very simple and absolutely correct. What about
Code:
ls -al $HOME/.tcshrc
? At this point it would be useful to know how do you login (graphical login, remote shell, by means of the su command and so on) even if the .tcshrc file should be sourced by every shell type.

Finally, please can you try to verify the tcsh package?
Code:
rpm -V tcsh
 
Old 07-16-2010, 10:41 AM   #15
deepti_114
LQ Newbie
 
Registered: Jul 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Yes i think it has something to do with the way i login.Its a university system with multiple user levels.I login remotely using ssh.
When i do: "ls -al $HOME/.tcshrc" - it says no such file.But its not at $HOME that is my working directory. Its /local/home/djain and its here that i have written a .tcshrc file which i think now is not the correct place to put it.

What if i write a simple script lets say myscript.sh in my working directory and write the same commands in it:

#myscript.sh
echo "hello world"
setenv SPARE_PLUGIN /local/home/djain/SPARE/SPARE/
setenv SPARE_PREFIX $SPARE_PLUGIN/build/native/gcc-build/install/
setenv DSWP_NPIPE=2

instead of trying to work around tcshrc and then chmod+x this script and run it manually after i login.
But it still does not work
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Set permanently Package configuration variables vofka Linux - General 1 07-05-2009 06:32 PM
Permanently Set Environment Variable LANG Mistro116@yahoo.com Red Hat 1 06-12-2008 08:11 PM
howto set system-wide environment variables permanently in debian vineet7kumar Linux - Newbie 2 05-08-2008 06:39 PM
How to set up an system wide environment variable permanently?? piyush.kansal Fedora 5 12-07-2007 04:04 AM
Help with the currently set environment variables!! apoc013 Linux - Newbie 6 01-21-2004 01:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration