From 579907714e2da750266e6dcf49090f2ccd39f1f9 Mon Sep 17 00:00:00 2001 From: strupo Date: Wed, 17 Nov 2021 13:26:43 +0000 Subject: [PATCH 1/4] Passing arguments in shebang on Linux (env -S) It is possible to pass arguments into commands in the shebang on Linux using the env(1) -S option. --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d55198566..23a079028 100644 --- a/README.md +++ b/README.md @@ -162,11 +162,17 @@ console.log("Hello, world!") ``` Passing CLI arguments via shebang is allowed on Mac but not Linux. For example, the following will fail on Linux: +### Passing CLI arguments via shebang - #!/usr/bin/env ts-node --files - // This shebang is not portable. It only works on Mac +- On Mac: -Instead, specify all ts-node options in your `tsconfig.json`. + #!/usr/bin/env ts-node --files + +- On Linux: + + #!/usr/bin/env -S ts-node --files + + The `-S` option for `env` processes and splits what comes after it into separate arguments; and is used to pass multiple arguments on shebang lines. ## Programmatic From dd429bad29ce6e5128ed66698b236987350f2839 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Fri, 21 Jan 2022 13:53:27 -0500 Subject: [PATCH 2/4] fix --- website/docs/usage.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/website/docs/usage.md b/website/docs/usage.md index ecd6721bc..b6fbeed98 100644 --- a/website/docs/usage.md +++ b/website/docs/usage.md @@ -35,14 +35,27 @@ ts-node-cwd script.ts console.log("Hello, world!") ``` -Passing CLI arguments via shebang is allowed on Mac but not Linux. For example, the following will fail on Linux: +Passing options via shebang requires the [`env -S` flag](https://manpages.debian.org/bullseye/coreutils/env.1.en.html#S), which is not available on old versions of `env`. +```typescript +#!/usr/bin/env -S ts-node --files +// This shebang works on Mac and Linux with newer versions of env +// Technically, Mac allows omitting `-S`, but Linux requires it ``` -#!/usr/bin/env ts-node --files -// This shebang is not portable. It only works on Mac + +To write scripts with maximum portability, [specify all options in your `tsconfig.json`](./configuration#via-tsconfigjson-recommended) and omit them from the shebang. + +```typescript +#!/usr/bin/env ts-node +// This shebang works everywhere ``` -Instead, specify all ts-node options in your `tsconfig.json`. +To test your version of `env` for compatibility: + +```shell +# Note that these unusual quotes are necessary +/usr/bin/env --debug '-S echo foo bar' +``` ## Programmatic From 3059e440815192e797842edc2ebd9e7d9b1472a5 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Fri, 21 Jan 2022 13:59:04 -0500 Subject: [PATCH 3/4] fix --- website/docs/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/usage.md b/website/docs/usage.md index b6fbeed98..91e994498 100644 --- a/website/docs/usage.md +++ b/website/docs/usage.md @@ -35,7 +35,7 @@ ts-node-cwd script.ts console.log("Hello, world!") ``` -Passing options via shebang requires the [`env -S` flag](https://manpages.debian.org/bullseye/coreutils/env.1.en.html#S), which is not available on old versions of `env`. +Passing options via shebang requires the [`env -S` flag](https://manpages.debian.org/bullseye/coreutils/env.1.en.html#S), which is available on recent versions of `env`. ([compatibility](https://github.com/TypeStrong/ts-node/pull/1448#issuecomment-913895766)) ```typescript #!/usr/bin/env -S ts-node --files From 1a5c5129fd040e455caee5445b2c57fad5f0d38d Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Fri, 21 Jan 2022 13:59:21 -0500 Subject: [PATCH 4/4] fix --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 23a079028..d55198566 100644 --- a/README.md +++ b/README.md @@ -162,17 +162,11 @@ console.log("Hello, world!") ``` Passing CLI arguments via shebang is allowed on Mac but not Linux. For example, the following will fail on Linux: -### Passing CLI arguments via shebang -- On Mac: + #!/usr/bin/env ts-node --files + // This shebang is not portable. It only works on Mac - #!/usr/bin/env ts-node --files - -- On Linux: - - #!/usr/bin/env -S ts-node --files - - The `-S` option for `env` processes and splits what comes after it into separate arguments; and is used to pass multiple arguments on shebang lines. +Instead, specify all ts-node options in your `tsconfig.json`. ## Programmatic