3

I have this interpreter, which prints the ARGS variable:

#!/bin/bash
echo "[$ARGS]"

I use this interpreter in another script:

#!/usr/bin/env ARGS=first interpreter

Calling the second script, I get

[first]

How do I get

[first second]

?

elsamuko
  • 668
  • 6
  • 16
  • 1
    See http://stackoverflow.com/questions/4303128/how-to-use-multiple-arguments-with-a-shebang-i-e regarding the whitespace issue in the Shebang. – tholu Jun 17 '14 at 20:39

1 Answers1

1

The short of it: don't rely on being able to pass multiple arguments as part of a shebang line, and the one argument you can use must be an unquoted, single word.

For more background information, see the question @tholu has already linked to in a comment (https://stackoverflow.com/a/4304187/45375).

Thus, I suggest you rewrite your other script to use bash as well:

#!/bin/bash

ARGS='first second' /usr/bin/env interpreter "$@"
  • This allows you to use bash's own mechanism for defining environment variables ad-hoc (for the command invoked and its children) by prefixing commands with variable assignments, allowing you to use quoting and even define multiple variables.
  • Whatever command-line arguments were passed in are passed through to interpreter via "$@".
Community
  • 1
  • 1
mklement0
  • 382,024
  • 64
  • 607
  • 775