|
|
|
|
|
|
| Author |
Message |
Matt *nix forums Guru Wannabe
Joined: 05 Mar 2005
Posts: 166
|
Posted: Thu Feb 10, 2005 8:32 pm Post subject:
.cshrc clobbers environment
|
|
|
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
|
Posted: Thu Feb 10, 2005 11:45 pm Post subject:
Re: .cshrc clobbers environment
|
|
|
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
|
Posted: Fri Feb 11, 2005 1:06 am Post subject:
Re: .cshrc clobbers environment
|
|
|
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
|
Posted: Fri Feb 11, 2005 1:56 am Post subject:
Re: .cshrc clobbers environment
|
|
|
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
|
Posted: Fri Feb 11, 2005 12:32 pm Post subject:
Re: .cshrc clobbers environment
|
|
|
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
|
Posted: Fri Feb 11, 2005 2:15 pm Post subject:
Re: .cshrc clobbers environment
|
|
|
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
|
Posted: Fri Feb 11, 2005 2:17 pm Post subject:
Re: .cshrc clobbers environment
|
|
|
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 |
|
 |
|
|
The time now is Fri Jan 09, 2009 12:45 am | All times are GMT
|
|
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
|
|