"bad file name" error if "shebang" script filename contains dash

XMLWordPrintable

    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      $ arch
      arm64

      $ sw_vers
      ProductName: macOS
      ProductVersion: 26.0.1
      BuildVersion: 25A362

      $ java -version
      openjdk version "25.0.1" 2025-10-21 LTS
      OpenJDK Runtime Environment Zulu25.30+17-CA (build 25.0.1+8-LTS)
      OpenJDK 64-Bit Server VM Zulu25.30+17-CA (build 25.0.1+8-LTS, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      If I create a "shebang" script where the filename contains a dash, I get a "bad file name" error when I run it. If I replace the dash in the filename with an underscore, either by renaming the script or by creating a symlink to the script and running the symlink, it works fine.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a file named "hello-world" containing the following:
      ----
      #!/usr/bin/env java --source 25

      void main() {
        IO.println("hello, world");
      }
      ----

      Make it executable:
      ----
      $ chmod +x hello-world
      ----

      Run it:
      ----
      $ ./hello-world
      ----

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected it to print "hello, world" and exit with a 0 exit status:
      ----
      $ ./hello-world
      hello, world
      $ echo $?
      0
      ----
      ACTUAL -
      Instead, it prints the following and exits with a nonzero exit status:
      ----
      $ ./hello-world
      ./hello-world:3: error: bad file name: hello-world
      void main() {
      ^
      1 error
      error: compilation failed
      $ echo $?
      1
      ----

      By creating a symlink to the file with the dash replaced with an underscore and then running the symlink, it works fine:
      ----
      $ ln -s hello-world hello_world
      $ ./hello_world
      hello, world
      ----

            Assignee:
            Christian Stein
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: