Invoking a bash shell with an export var

Hello all,

How can I invoke the bash shell (via command line) to execute another command by setting an exported environmental variable on the fly (as this env var would be used by the command -another script, the bash would execute).

This needs to be done in one single line as the same would go into a make file to build something.

I hope something like this:

#/bin/bash "export ABC=pqr" ./my_commandScript_using_the_exportedVarABC

Maybe something like would do the trick:-

/bin/bash -c "export ABC=pqr ; ./my_commandScript_using_the_exportedVarABC"

Does that help?

Robin

1 Like

Try:

ABC=pqr bash ./my_commandScript_using_the_exportedVarABC

or if the script is executable (and has #!/bin/bash as the shebang or if bash is the current shell)

ABC=pqr ./my_commandScript_using_the_exportedVarABC
2 Likes

Thanks all!

/bin/bash -c "" seems to work; though I had tried in simple tests and were expecting that ps -aef | grep bash would show another bash. Guess it just executes and goes off.

To give the context, I was looking for this is that we have a make file which calls for autoconf ./configure along with some arguments for the configure script (in a single line). This by-default looks for the gcc compiler where as I want the configure script to take IBM's xlc compiler (my platform being an AIX machine). Somewhere, I came to know that the configure scripts would look for exported value of CC to decide on the compiler to be used in the makefile generated by it.

Hence, I needed to call bash before ./configure and set the environment var CC for the path of the xlc (on the same line); this was to me without luck and made me to look for your help.

Thanks, I'll try once again tomorrow morning and would update across.

Thanks! That worked.