Skip to main content
Link to the LWN article.
Source Link
Stephen Kitt
  • 484k
  • 60
  • 1.2k
  • 1.4k

The arguments to the interpreter in this case are the arguments constructed after interpretation of the shebang line, combining the shebang line with the script name and its command-line arguments.

Thus, an AWK script starting with

#! /usr/bin/awk -f 

named myscript and called as

./myscript file1 file2 

results in the actual arguments

/usr/bin/awk -f ./myscript file1 file2 

The single optional argument is -f in this case. Not all interpreters need one (see /bin/sh for example), and many systems only allow at most one (so your shebang line won’t work as you expect it to). The argument can contain spaces though; the whole content of the shebang line after the interpreter is passed as a single argument.

To experiment with shebang lines, you can use #! /bin/echo (although that doesn’t help distinguish arguments when there are spaces involved).

See How programs get run for a more detailed explanation of how shebang lines are processed (on Linux).

The arguments to the interpreter in this case are the arguments constructed after interpretation of the shebang line, combining the shebang line with the script name and its command-line arguments.

Thus, an AWK script starting with

#! /usr/bin/awk -f 

named myscript and called as

./myscript file1 file2 

results in the actual arguments

/usr/bin/awk -f ./myscript file1 file2 

The single optional argument is -f in this case. Not all interpreters need one (see /bin/sh for example), and many systems only allow at most one (so your shebang line won’t work as you expect it to).

To experiment with shebang lines, you can use #! /bin/echo.

The arguments to the interpreter in this case are the arguments constructed after interpretation of the shebang line, combining the shebang line with the script name and its command-line arguments.

Thus, an AWK script starting with

#! /usr/bin/awk -f 

named myscript and called as

./myscript file1 file2 

results in the actual arguments

/usr/bin/awk -f ./myscript file1 file2 

The single optional argument is -f in this case. Not all interpreters need one (see /bin/sh for example), and many systems only allow at most one (so your shebang line won’t work as you expect it to). The argument can contain spaces though; the whole content of the shebang line after the interpreter is passed as a single argument.

To experiment with shebang lines, you can use #! /bin/echo (although that doesn’t help distinguish arguments when there are spaces involved).

See How programs get run for a more detailed explanation of how shebang lines are processed (on Linux).

Source Link
Stephen Kitt
  • 484k
  • 60
  • 1.2k
  • 1.4k

The arguments to the interpreter in this case are the arguments constructed after interpretation of the shebang line, combining the shebang line with the script name and its command-line arguments.

Thus, an AWK script starting with

#! /usr/bin/awk -f 

named myscript and called as

./myscript file1 file2 

results in the actual arguments

/usr/bin/awk -f ./myscript file1 file2 

The single optional argument is -f in this case. Not all interpreters need one (see /bin/sh for example), and many systems only allow at most one (so your shebang line won’t work as you expect it to).

To experiment with shebang lines, you can use #! /bin/echo.