Ignore variables from another shell

0

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

Marc-Olivier Titeux

Posted 2012-08-08T12:47:40.080

Reputation: 171

Answers

2

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.

chepner

Posted 2012-08-08T12:47:40.080

Reputation: 5 645

That is exactly what I was looking for! Thanks! – Marc-Olivier Titeux – 2012-08-10T08:01:59.870

0

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.

okobaka

Posted 2012-08-08T12:47:40.080

Reputation: 305

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 – Marc-Olivier Titeux – 2012-08-08T13:56:24.350

so after ./bash --login execute this source .bash_profile – okobaka – 2012-08-08T14:14:14.173

Same result unfortunately... – Marc-Olivier Titeux – 2012-08-08T14:33:50.747

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 – 2012-08-08T14:45:01.857

Well, I looked into the switch (actually, I tried them all, but with no luck). I thought of unsetting any one of them, but there are quite of them. Anyway, thanks for your help. – Marc-Olivier Titeux – 2012-08-08T15:03:22.143

1Print them all: env | awk -F= '/^\w/ {print $1}' | xargs, then remove those important one and unset. – okobaka – 2012-08-08T15:24:56.920

okobaka I am going to accept @chepner's solution, which does better suit my needs. Thanks again for helping me! – Marc-Olivier Titeux – 2012-08-10T08:15:33.397