c12
c12

Reputation: 9827

Environment Variable Creation for All Unix Shells

I'm trying to add some export statements in my Unix shell script and up to this point I've only gotten it to work with the bash shell. Is there a way to make the below export apply in all shells using shell scripting?

AXIS2_HOME=/home/user/axis2-1.6.0 export AXIS2_HOME

Upvotes: 0

Views: 101

Answers (1)

John3136
John3136

Reputation: 29266

What do you mean "all shells?"

  • If you mean different shells as in "can I change my parent/sibling shell's environment"?

Then no, you can't. Exporting a var should mean all your children inherit it though. You can go some way to faking it by having your script create a temp file that you somehow get the caller to execute, but it's starting to get a biut weird and suggests a problem in your architecture.

  • If you mean different shells as in sh/bash/csh/tcsh/zsh/ksh etc

You can make something like that work in all "sh" flavour shells, but for "csh" flavours you need to use setenv.

Depending how far you want to go, you could write something to store all your env. vars in a separate file (e.g. env.dat) and convert that to sh/csh syntax using sed/awk/perl.

Upvotes: 1

Related Questions