niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
.cshrc clobbers environment
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
Matt
*nix forums Guru Wannabe


Joined: 05 Mar 2005
Posts: 166

PostPosted: Thu Feb 10, 2005 8:32 pm    Post subject: .cshrc clobbers environment Reply with quote

Hi,

I have a .cshrc file and a .special file in my home directory. The
..cshrc has the usual stuff, sets my path etc. All is good.

I use a piece of software requiring a whole different environment,
defined in the .special file. It sets a shedload of environment
variables, and appends all sorts of things to my path. Before
launching this application, I source $HOME/.special and all is good.

Now, I have an option to spin off an xterm from within this
application. The idea is that the xterm inherits the 'special'
environment. It would be like starting a new shell and typing source
$HOME/.special. I need it so that users can run some special commands
etc, which require the special path, in this xterm without having to
do the source thing.

The trouble is getting the xterm. If I just issue the command 'xterm'
from within the app, the xterm pops up but its environment is
clobbered by the user's .cshrc file. So, I tried doing 'xterm -e
special' and having a script in the ordinary path called special which
does the source. This works like a charm, but unfortunately the xterm
disappears as soon as it's done sourcing. I need the xterm to stick
around until 'exit' is issued by the user.

I understand there is an option for xterm '-hold' in some Linux
distributions which does what I need. But that doesn't work for me.

In a nutshell, I'd like 'xterm' to source something other than .cshrc
just this one time.

Can anyone help?
Cheers,
Matt
Back to top
Icarus Sparry
*nix forums Guru


Joined: 19 Feb 2005
Posts: 342

PostPosted: Thu Feb 10, 2005 11:45 pm    Post subject: Re: .cshrc clobbers environment Reply with quote

On 2005-02-10, Matt <post@red-brick.com> wrote:
Quote:
Hi,

I have a .cshrc file and a .special file in my home directory. The
.cshrc has the usual stuff, sets my path etc. All is good.

I use a piece of software requiring a whole different environment,
defined in the .special file. It sets a shedload of environment
variables, and appends all sorts of things to my path. Before
launching this application, I source $HOME/.special and all is good.

Now, I have an option to spin off an xterm from within this
application. The idea is that the xterm inherits the 'special'
environment. It would be like starting a new shell and typing source
$HOME/.special. I need it so that users can run some special commands
etc, which require the special path, in this xterm without having to
do the source thing.

The trouble is getting the xterm. If I just issue the command 'xterm'
from within the app, the xterm pops up but its environment is
clobbered by the user's .cshrc file. So, I tried doing 'xterm -e
special' and having a script in the ordinary path called special which
does the source. This works like a charm, but unfortunately the xterm
disappears as soon as it's done sourcing. I need the xterm to stick
around until 'exit' is issued by the user.


In a nutshell, I'd like 'xterm' to source something other than .cshrc
just this one time.

You either want

xterm -e csh -f

which will start an csh without reading anything. So this will inherit
the environment, which includes the path, but not aliases etc,
or

xterm -e csh -c "source .special; csh -f"

This will start a non-interactive csh, which will read .cshrc and then
..special, and then start an interactive csh, which will not read
anything. Again you will not have aliases.

If you need aliases, then I suggest you look into something like
'expect'.

#!/usr/bin/expect
spawn /bin/csh
send "source special\r"
interact
Back to top
Bruce Barnett
*nix forums Guru


Joined: 21 Feb 2005
Posts: 324

PostPosted: Fri Feb 11, 2005 1:06 am    Post subject: Re: .cshrc clobbers environment Reply with quote

post@red-brick.com (Matt) writes:

Quote:
In a nutshell, I'd like 'xterm' to source something other than .cshrc
just this one time.


Well, you can also see why it clobbers the environment and try to work
around it.

You could define an environment variable, and then test it in your new xterm.
For instance, only redefine your environment under certain conditions

i.e.
setenv CHANGEENVIRONMENT
xterm &


where your .cshrc file has:
-----------------
# ~/.cshrc
# Normally I exit if non-interactive, or not attached to a terminal.

if ( ! ( $?USER && $?prompt && $?TERM )) exit
set echo # debug
set verbose # debug
if ( $TERM !~ "xterm" ) then
Only do this if you don't use an xterm
if ( ! ( $?CHANGEENVIRONMENT ) ) source $HOME/.special
fi
#etc.
-------------


If you don't define the variable, nothing happens.



--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Back to top
Barry Margolin
*nix forums Guru


Joined: 24 Feb 2005
Posts: 323

PostPosted: Fri Feb 11, 2005 1:56 am    Post subject: Re: .cshrc clobbers environment Reply with quote

In article <3c5e0c78.0502101332.5185403c@posting.google.com>,
post@red-brick.com (Matt) wrote:

Quote:
I have a .cshrc file and a .special file in my home directory. The
.cshrc has the usual stuff, sets my path etc. All is good.

Probably many of these things should be done in .login rather than
..cshrc. .login is only executed by the initial login shell, not every
shell created thereafter. Anything that's automatically inherited by
subshells only needs to be done once; .cshrc only has to contain things
that must be done fresh in each shell process (e.g. aliases).

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Back to top
Bruce Barnett
*nix forums Guru


Joined: 21 Feb 2005
Posts: 324

PostPosted: Fri Feb 11, 2005 12:32 pm    Post subject: Re: .cshrc clobbers environment Reply with quote

Barry Margolin <barmar@alum.mit.edu> writes:

Quote:
Probably many of these things should be done in .login rather than
.cshrc. .login is only executed by the initial login shell, not every
shell created thereafter. Anything that's automatically inherited by
subshells only needs to be done once;

Agreed. I usually set my search path and environ variables in the
..login file. This way, I can have terminal windows with different
environments, or use the default.

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Back to top
Matt
*nix forums Guru Wannabe


Joined: 05 Mar 2005
Posts: 166

PostPosted: Fri Feb 11, 2005 2:15 pm    Post subject: Re: .cshrc clobbers environment Reply with quote

Icarus Sparry <usenet@icarus.freeuk.com> wrote in message news:<slrnd0o01b.6qk.usenet@icarus.freeuk.com>...
Quote:
On 2005-02-10, Matt <post@red-brick.com> wrote:
edit
In a nutshell, I'd like 'xterm' to source something other than .cshrc
just this one time.

edit

xterm -e csh -c "source .special; csh -f"

This will start a non-interactive csh, which will read .cshrc and then
.special, and then start an interactive csh, which will not read
anything. Again you will not have aliases.

edit


Icarus...

That works a treat --- thanks very much. I did not think of looking at csh itself.

Cheers,
Matt
Back to top
Matt
*nix forums Guru Wannabe


Joined: 05 Mar 2005
Posts: 166

PostPosted: Fri Feb 11, 2005 2:17 pm    Post subject: Re: .cshrc clobbers environment Reply with quote

post@red-brick.com (Matt) wrote in message news:<3c5e0c78.0502101332.5185403c@posting.google.com>...
<edit>
Quote:
In a nutshell, I'd like 'xterm' to source something other than .cshrc
just this one time.
edit


Hi,

Thanks very much for all of your suggestions. I am not in control of
the complete environment here, which limits what I can do to some
extent, but I will probably try elements from all of your posts.

Thanks again,
Matt
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Fri Jan 09, 2009 12:45 am | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts User Environment - export PATH variable paalepu AIX 0 Tue Sep 12, 2006 8:12 pm
No new posts Removing db from environment mike.klaas@gmail.com Berkeley DB 0 Fri Jul 21, 2006 5:14 am
No new posts restricted environment Gabriele *darkbard* Farin python 7 Wed Jul 19, 2006 11:06 pm
No new posts mod_perl and access to the parent processes environment? Robert Nicholson modules 3 Wed Jul 19, 2006 8:41 pm
No new posts Bug#378907: ITP: tet -- Test Environment Toolkit from the... Stuart Anderson devel 0 Wed Jul 19, 2006 5:10 pm

Debt Consolidation | Debt Consolidation | Credit Cards UK | Bankruptcy | Magazine Subscriptions
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3642s ][ Queries: 16 (0.2649s) ][ GZIP on - Debug on ]