Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Last active August 29, 2015 14:26
Show Gist options
  • Save jhrcz/5b6612b9591d3adcd27c to your computer and use it in GitHub Desktop.
Save jhrcz/5b6612b9591d3adcd27c to your computer and use it in GitHub Desktop.
use interpreter like python based on script path

script has the same shebang in all cases. it depends on the path to the script which interpreter is used

no special environment setup, not additional wrappers, without changing shebang in scripts

just one configuration file/directory to specify which tool should use which environment. compatible with SCL, virtualenv and other available ways to get different version in one system

#!./python

to simulate the same tool in different path, i use symlink a or b to the original script.sh

case 1:

$ ./a
running in 2.5

case 2:

$ ./b
running in 2.6
script.sh
script.sh
#!/bin/bash
case $1 in
./a)
i=python2.5
;;
./b)
i=python2.6
;;
esac
exec ./$i "$@"
#!/bin/bash
echo running in 2.5
s=$1
export I=2.5
shift
bash "$@"
#!/bin/bash
echo running in 2.6
s=$1
export I=2.6
shift
bash "$@"
#!./python
echo $I
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment