Is it possible to set an ENV variable for just one shell command (ie make it expire right after the command executes)?

For example:

export VERSIONER_PYTHON_PREFER_32_BIT=yes
winpdb

I'd like to set my system to use 32bit Python for just this command, then go back to 64bit. Maybe something like

VERSIONER_PYTHON_PREFER_32_BIT=yes; winpdb

Thanks!

link|improve this question

64% accept rate
The [python] tag should only be used when the question directly relates to Python (e.g. it is written in Python). The same idea applies to tags in general. – Josh Sep 9 '10 at 20:45
I think the [shell] tag should be more specific ([bourne-shell] I assume). – Josh Sep 9 '10 at 20:46
feedback

3 Answers

up vote 8 down vote accepted

in Bash, you can do VERSIONER_PYTHON_PREFER_32_BIT=yes winpdb and the env variable is set for the command. Same as you propose but without semi-colon.

link|improve this answer
There's also the "env" command, which exists for exactly this purpose. But yes, if you're already at a shell prompt, it's easier to just to "ENV=foo cmd". – Teddy Oct 24 '09 at 21:40
feedback

Run it in a subshell. so (export VERIONSER_PYTHONG_PREFER_32_BIT=YES; winpdb)

link|improve this answer
feedback

Put parenthesis around the command:

(export VARNAME=value; cmd1; cmd2; cmd3)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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