If the offending tool is lame enough to call /bin/sh
directly, instead of respecting your system setup by using /usr/bin/env sh
, your options are very limited. I originally thought you'd be able to basically do what virtual environments do for Python, but after attempting to write a script that did so I couldn't get around the direct call to /bin/sh
via any $PATH
magic.
- Before calling the tool, re-symlink sh to bash, then undo your change after the call to the tool.
- Better yet, change your assumption that you can't edit the tool. What's the tool? If it's open source, which it seems like it is given you have some knowledge of how it works, fork it, change it to use
/usr/bin/env sh
and submit a pull request. Huzzah for open source contributions!
If the offending tool isn't actually calling /bin/sh
directly, as your recent comment may indicate, the following should work.
#!/usr/bin/env sh
BASH_VENV_HOME=$HOME/.bash_venv
if [ ! -d $BASH_VENV_HOME ]; then
mkdir $BASH_VENV_HOME
fi
# Make an `sh` binary in the front of your path that points to bash
if [ ! -e $BASH_VENV_HOME/sh ]; then
ln -s /bin/bash $BASH_VENV_HOME/sh
fi
orig_path=$PATH
PATH=$BASH_VENV_HOME:$PATH
# Call your tool
# Reset path
PATH=orig_path
The tool, should it execute sh
, will then find the one in the front of your path, which is a symlink to bash.