Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am on a linux workstation in a network, with an "old" distrib. Furthermore, login shell is enforced to CSH. I already asked to Admins if it would be possible to switch to another one (I would like to have bash), but it was a no-go...

Therefore, I am running bash from the command line, as an interactive non-login shell (actually I am using gnome and gnome-terminal with a profile that runs /bin/bash -i as the command). A lot, if not all of my scripts use bash so I run them from it invoking bash with a script. It is messy but it works.

I have .cshrc with environment variables, aliases and options for csh defined in a .login and a .cshrc files in my $HOME. I also have a .bashrc/.bash_profile(that redirects to .bashrc if this an interactive shell)/.bash_aliases with some other variables and some that are the same. When I run the bash shell, I inherit from the environments variables defined in my .login file. I would like to ignore everything that is set up in this one when I run bash.

I would like to know if there is an option to run bash, ignoring every other environment variables previously defined from my CSH login session when I run my BASH shell.

Do you have any ideas?

Thank you

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Instead of manually unsetting variables you don't want to inherit, run bash using the env command:

env -i bash

The -i flag causes bash to ignore its inherited environment.

share|improve this answer
    
That is exactly what I was looking for! Thanks! –  mot Aug 10 '12 at 8:01
add comment

You want to run bash as non-interactive shell, inside CSH, with bash variables defined in .bash_profile right?

You could give a shoot:

./bash --login
source ./bash --login

but i can't test it.

share|improve this answer
    
Thanks for answering. It did not do what I'd like too: a setenv $PLOUC "PLOUZ" defined in .cshrc is still giving me a PLOUZ when I do a echo $PLOUC after /bin/bash --login –  mot Aug 8 '12 at 13:56
    
so after ./bash --login execute this source .bash_profile –  okobaka Aug 8 '12 at 14:14
    
Same result unfortunately... –  mot Aug 8 '12 at 14:33
    
Bash itself could inherit var from environment that was executed from, look for proper switch in man bash. If you just want to remove variables from the enviroment just unset VARNAME1 VARNAME2. –  okobaka Aug 8 '12 at 14:45
1  
Print them all: env | awk -F= '/^\w/ {print $1}' | xargs, then remove those important one and unset. –  okobaka Aug 8 '12 at 15:24
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.