0

I have a file test with the content

#!/bin/sh -c 'echo was called with $0'

I if i execute it it with ./test, i would expect the OS to effectively execute

sh -c 'echo was called with $0' ./test

which to my understanding should result in was called with ./test.

However, i get the error message

/bin/sh: 0: Illegal option -

What is the reason for this Error?

please note that i understand that there are easier ways to print the arguments, the echo part is a stand-in for unrelated and more complex things.

Added information: cat -E test gives me

#!/bin/sh -c 'echo was called with $0'$
$
keppla
  • 173
  • 5
  • @msp9011 i tested it in 2 docker containers: ubuntu:latest and alpine:latest. What is your setup? – keppla Aug 02 '19 at 12:38
  • if i replace `/bin/sh` with `/bin/echo`, it prints the rest of the shebang, since that works, i guess it's nothing general like lineendings but something sh-specific – keppla Aug 02 '19 at 12:47
  • 1
    Linux only supports one argument on the hashbang line, see [Multiple arguments in shebang](https://unix.stackexchange.com/q/399690/170373), [Shebang line with `#!/usr/bin/env command --argument` fails on Linux](https://unix.stackexchange.com/q/63979/170373) and then there's [Sven Mascheck's page](https://www.in-ulm.de/~mascheck/various/shebang/) about hashbang differences in different systems, with more information you ever want to know. – ilkkachu Aug 02 '19 at 13:22

0 Answers0