开发者

Multiple init files for a new Bash session

I'm writing a script that is going exec a new bash session. Based on some logic, it finds an init script that will be used for the new shell. I'm wondering if there is a nice way to tell the new bash session to use the found init script for initialization in addition to the system initialization scripts. The --init-file option seems to call for a replacement file rather than an additional one.

Currently, I've got a messy setup开发者_开发知识库 with an environment variable containing the path to the found init scrip which gets sourced in a wrapper init file, along with the system files. Is something like

exec bash --init-file "/etc/profile;~/.bashrc;${myInit}" possible?

Thanks, Andrew


This stands a good chance of working:

exec bash --init-file <(cat /etc/profile ~/.bashrc "${myInit}")


I'm not able to test this on my machine, but perhaps you could pass a custom .bashrc or .bash_profile to your subshell, sourcing the 'init' file with something like

if [ -f path_to_init ]; then
  . path_to_init_file
fi
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜