1

Is there any way for changing the interpreter in the middle of a bash script

For instance start with:

#!/bin/bash

Later change to:

#!$drush_location

The reason is because I want to use bash to resolve the location of drush using bash and then pass that var in as an interpreter

Botto
  • 1,188
  • 4
  • 16
  • 29
  • But if you specify a *different* command interpreter in the shebang line, how will `bash` get a chance to resolve anything? This is not changing the interpreter in the middle of a `bash` script -- with a different interpreter, it's no longer a `bash` script. – pavium Jun 02 '11 at 09:53

1 Answers1

3

You will need to write two scripts and use the first (bash) one to launch the second (drush).

There are other ways to accomplish this, but they are all basically fancy ways of doing the above. For example you could use a here-doc to cram a script contained as a string in your first script into stdin on drush and have it execute that, or even write a temporary file and execute that as a script, but you have to run two processes somehow, you can't change the interpreter on the fly.

Really the thing to do would be to fix your environment so that it can find drush. Then you can use:

#!/usr/bin/env drush

As the hashbang for your drush script. If your system evn can't find it, then fix your search paths until it can!

Caleb
  • 5,084
  • 1
  • 46
  • 65