Is there any way to dynamically choose the interpreter that's executing a script? I have a script that I'm running on two different systems, and the interpreter I want to use is located in different locations on the two systems. What I end up having to to is change the hashbang line every time I switch over. I would like to do something that is the logical equivalent of this (I realize that this exact construct is impossible):
if running on system A:
#!/path/to/python/on/systemA
elif running on system B:
#!/path/on/systemB
#Rest of script goes here
Or even better would be this, so that it tries to use the first interpreter, and if it doesn't find it uses the second:
try:
#!/path/to/python/on/systemA
except:
#!path/on/systemB
#Rest of script goes here
Obviously, I can instead execute it as
/path/to/python/on/systemA myscript.py
or
/path/on/systemB myscript.py
depending on where I am, but I actually have a wrapper script that launches myscript.py
, so I would like to specify the path to the python interpreter programmatically rather than by hand.
if
condition is not an option for you ? like,if something; then /bin/sh restofscript.sh elif...