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

1
  • 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. Commented Jun 2, 2011 at 9:53

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.