If you want to set an env variable in bash for only 1 command, here’s some bad ways to do it:
|
|
Problem: What if FOO was already set?
How about…
|
|
Problem: Ok, now you revert FOO to its original value, but what a pain in the ass!
How about…
|
|
Well, that certainly works. ()
creates a new environment by
calling fork() but that’s pretty heavyweight.
How about…
|
|
What???
Yes, that sets FOO, exports it, and only sets it for the execution of one command. You can even set more variables.
|
|
This is the second least known feature of bash. I’ll write about what I think is the least know feature in my next blog post.
Enjoy!