3

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?

dacracot
  • 143

2 Answers2

4

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'
Ryan Babchishin
  • 443
  • 3
  • 9