diff --git a/website/docs/commands/shebang.md b/website/docs/commands/shebang.md index 4840145ee6..803ca6ab3b 100644 --- a/website/docs/commands/shebang.md +++ b/website/docs/commands/shebang.md @@ -5,6 +5,8 @@ sidebar_position: 30 This command is equivalent to `run`, but it changes the way Scala CLI parses options (used to configure the tool) and inputs (the sources of your project) in order to be compatible with `shebang` scripts. +The command `shebang` also allows script files to be executed even if they have no file extension, +provided they start with the [`shebang` header](../guides/shebang.md#shebang-script-headers). Normally, inputs and `scala-cli` options can be mixed. Program arguments (to be passed to your app) have to be specified after `--` (double dash) separator. diff --git a/website/docs/guides/shebang.md b/website/docs/guides/shebang.md index 086b26560c..4e4e16cd21 100644 --- a/website/docs/guides/shebang.md +++ b/website/docs/guides/shebang.md @@ -19,7 +19,7 @@ println(args.size) println(args.headOption) ``` -And it works almost correctly. +And it works correctly: @@ -40,7 +40,7 @@ None -And it also works. +And it also works: @@ -173,4 +173,61 @@ world: not found world: not found --> + + +### Script files' extensions + +When running the `shebang` subcommand, script files don't need the `.sc` extension, +but they are then REQUIRED to start with a shebang line: + +```scala title=hello-with-shebang +#!/usr/bin/env -S scala-cli shebang -S 3 + +println(args.size) +println(args.headOption) +``` + + + +```bash +chmod +x hello-with-shebang +./hello-with-shebang Hello World +``` + +```text +2 +Some(Hello) +``` + + + + +```scala title=hello-no-shebang +println(args.size) +println(args.headOption) +``` + + + +```bash +chmod +x hello-no-shebang +./hello-no-shebang Hello World +``` + +```text +hello-no-shebang does not contain shebang header +possible fixes: + Add '#!/usr/bin/env scala-cli shebang' to the top of the file + Add extension to the file's name e.q. '.sc' +``` + + \ No newline at end of file