I am trying to write a .bashrc file such that files using the #!/usr/bin/env shebang will have their PATH adjusted based on the directory in which they reside.
I've got something towards what I want with the following in my ~/.bashrc:
function env() {
case $PWD/ in
/var/www/php73/*)
PATH=~/bin73;;
/var/www/php8.1/*)
PATH=~/bin81;;
esac
/usr/bin/env "$@"
}
Then if I call env from /var/www/php73 or any subdirectory I get ~/bin73 included in the path as I want.
The problem is that this doesn't work for files which use the shebang #!/usr/bin/env as .bashrc is only defining a function for env, not the env program with its full path.
Is it possible to get .bashrc to modify PATH when the shebang is used? And if so, how?