1

I need a special shell environment set up to interact with an commercial application that we have purchased. The environment is queried "on the fly" from the application.

So I've attempted to start the shell with a script that has commands passed to it.

/bin/bash -c '/opt/xyq/commercialApp/bin/tool getEnv > ~/setAppEnv; . ~/setAppEnv; . ~/setMyEnv;'

This works... I get the special environment, source it, and then source my own environment... but then the shell exits.

How do I get it to stay within that second bash shell until I exit?

3

You can use --rcfile to specify an alternative to .bashrc at start up. This may be usable in your setup:

/opt/xyq/commercialApp/bin/tool/getEnv > ~/setAppEnv
cat ~/setMyEnv >> ~/setAppEnv
bash --rcfile ~/setAppEnv

If you also want to load .bashrc then this can be added after the cat command. You can then make this into a function

runApp()
{
  /opt/xyq/commercialApp/bin/tool/getEnv > ~/setAppEnv
  cat ~/setMyEnv >> ~/setAppEnv
  echo '[[ -e ~/.bashrc ]] && . ~/.bashrc' >> ~/setAppEnv
  bash --rcfile ~/setAppEnv
}
3

How about this? It starts a new bash, with the new environment variables set.

/bin/bash -c '/opt/xyq/commercialApp/bin/tool getEnv > ~/setAppEnv; . ~/setAppEnv; . ~/setMyEnv; bash'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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