Skip to content

Allow env to have flags and variables in shebang#2145

Merged
koalaman merged 1 commit intokoalaman:masterfrom
avdv:fix-2143
Feb 23, 2021
Merged

Allow env to have flags and variables in shebang#2145
koalaman merged 1 commit intokoalaman:masterfrom
avdv:fix-2143

Conversation

@avdv
Copy link
Copy Markdown
Contributor

@avdv avdv commented Feb 12, 2021

The env command has a -S,--split-string option which enables having arguments for the command in a shebang.

Also, one can use variable assignments for the command since env treats only the first word without a = character as the
program to run.

Fixes #2143.

The `env` command has a `-S,--split-string` option which enables
having arguments for the command in a shebang.

Also, one could use variable assignments for the command since
`env` treats only the first word without a `=` character as the
command to run.

Fixes koalaman#2143.
@koalaman koalaman force-pushed the master branch 12 times, most recently from d2b928f to 15ff87c Compare February 15, 2021 06:20
@koalaman koalaman merged commit 670c1de into koalaman:master Feb 23, 2021
@koalaman
Copy link
Copy Markdown
Owner

Thanks!

@avdv avdv deleted the fix-2143 branch February 23, 2021 06:29
@matthewpersicowork
Copy link
Copy Markdown

What OS is that on? I've never seen that.

@avdv
Copy link
Copy Markdown
Contributor Author

avdv commented Feb 23, 2021

What OS is that on? I've never seen that.

This is from GNU coreutils' env. See http://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#env-invocation

So, this applies to Linux, Hurd, probably darwin and windows with cygwin / mingw and so on.

FreeBsd has this too: https://www.unix.com/man-page/FreeBSD/1/env/

Kangie pushed a commit to Kangie/shellcheck that referenced this pull request Feb 27, 2023
Merge of upstream through b68df18

Conflicts:
	src/ShellCheck/Analytics.hs
	src/ShellCheck/Checks/Commands.hs

Manual changes:
	Removed now-redundant copies of arguments function.

Changelog:
----------------------------------------------------------------
Artur Klauser (1):
      Simplify .prepare-deploy

Austin English (1):
      add support for `/bin/busybox sh` shebang

Claudio Bley (1):
      Allow `env` to have flags and variables in shebang

George Plymale II (1):
      add macports as installation option in README.md

Joseph C. Sible (14):
      Remove unnecessary use of Maybe from shellFor
      Simplify parser
      Simplify parseArgs
      Simplify actualArgs
      Use mapM_ instead of reimplementing it
      Implement groupByLink in terms of foldr
      Use mapM instead of reimplementing it
      Use syntactic sugar instead of building lists by hand
      Use find
      Fuse map into any
      Use execState instead of snd . runState
      Remove redundant bind and return
      Remove unused helper stub
      Fuse maps

Keith Smiley (1):
      Add readonly to SC2155

Kir Kolyshkin (1):
      Whitelist podman for SC2016 about '$var'

Luke Davis (1):
      Add conda install instructions

Martin Bagge / brother (1):
      Change error 2076 to a warning.

Matthias Diener (1):
      Clarify 'which'

Moritz Röhrich (1):
      Error on backslash in comment   koalaman#2132

Pepe Iborra (1):
      Add Haddock markup to SystemInterface

Viacheslav Vasilyev (1):
      suppress ntlm error messages in Windows build

Vidar Holen (36):
      Recognize `local -x` similarly to `export` (fixes koalaman#2069)
      Rewrite getopts style option parser
      SC2267: Warn about xargs -i (fixes koalaman#2058)
      Use getopts parser to find 'read' arrays (fixes koalaman#2073)
      Optional style warning about [ x$var = xval ]
      Merge pull request koalaman#2077 from keith/ks/readonly-masking
      SC2095: Also warn if the command is backgrounded
      Add POSIX checks for more Bash-specific variables (fixes koalaman#2093)
      Merge pull request koalaman#2097 from ylluminarious/patch-1
      Merge pull request koalaman#1899 from ArturKlauser/simplify-prepare-deploy
      Merge pull request koalaman#1857 from lukelbd/conda-install-instructions
      Improve handling of trailing tokens for []/compounds (fixes koalaman#2091)
      Warn when a variable is assigned to itself
      Support env -S/--split-string in shebangs (fixes koalaman#2105)
      Treat 'exec $1' like '$1' for the purpose of quoting (fixes koalaman#2068)
      Improve checks for = in command names (fixes koalaman#2102)
      Don't treat ${!x@} as reference of x (fixes koalaman#2116)
      Escape control characters when adding user data to messages
      Parse heredocs correctly with carriage returns (fixes koalaman#2103)
      Improve SC2283 message and position
      Merge pull request koalaman#2119 from josephcsible/refactors
      Brand New Build!
      Merge pull request koalaman#2145 from avdv/fix-2143
      Merge pull request koalaman#2117 from brother/patch-1
      Merge pull request koalaman#2122 from freddii/master
      Merge pull request koalaman#2134 from kolyshkin/podman-sc2016
      Fix missing +x with new cabal and use previous release deps for caching
      Merge branch 'busybox' of https://github.com/austin987/shellcheck into austin987-busybox
      Merge parser and analyzer shebang parsing
      Merge branch 'austin987-busybox'
      Merge pull request koalaman#2112 from pepeiborra/patch-1
      Merge pull request koalaman#2166 from avoidik/patch-1
      Merge branch 'comment-backslash' of https://github.com/m-ildefons/shellcheck into m-ildefons-comment-backslash
      Improve warnings on backslashes in comments
      Merge branch 'm-ildefons-comment-backslash'
      Merge pull request koalaman#2181 from matthiasdiener/patch-1

freddii (1):
      fixed typing mistakes in changelog

 .compile_binaries                     |  73 -------
 .github/workflows/build.yml           | 124 +++++++++++
 .github_deploy                        |  35 +--
 .multi_arch_docker                    |   9 +-
 .prepare_deploy                       |  49 ++---
 .travis.yml                           |  97 ---------
 CHANGELOG.md                          |  11 +-
 Dockerfile                            |  29 ---
 README.md                             |   8 +
 build/README.md                       |  13 ++
 build/build_builder                   |  12 ++
 build/darwin.x86_64/Dockerfile        |  31 +++
 build/darwin.x86_64/build             |  14 ++
 build/darwin.x86_64/tag               |   1 +
 build/linux.aarch64/Dockerfile        |  30 +++
 build/linux.aarch64/build             |  15 ++
 build/linux.aarch64/tag               |   1 +
 build/linux.armv6hf/Dockerfile        |  59 +++++
 build/linux.armv6hf/build             |  16 ++
 build/linux.armv6hf/tag               |   1 +
 build/linux.x86_64/Dockerfile         |  26 +++
 build/linux.x86_64/build              |  15 ++
 build/linux.x86_64/tag                |   1 +
 build/run_builder                     |  30 +++
 build/windows.x86_64/Dockerfile       |  27 +++
 build/windows.x86_64/build            |  19 ++
 build/windows.x86_64/tag              |   1 +
 shellcheck.hs                         |   2 +-
 src/ShellCheck/ASTLib.hs              | 191 ++++++++++++++--
 src/ShellCheck/Analytics.hs           | 395 +++++++++++++++++++++++++++++++---
 src/ShellCheck/AnalyzerLib.hs         |  59 +++--
 src/ShellCheck/Checks/Commands.hs     |  61 +++++-
 src/ShellCheck/Checks/ShellSupport.hs |   8 +-
 src/ShellCheck/Interface.hs           |   6 +-
 src/ShellCheck/Parser.hs              | 155 +++++++------
 test/shellcheck.hs                    |   2 +
 36 files changed, 1188 insertions(+), 438 deletions(-)
 delete mode 100755 .compile_binaries
 create mode 100644 .github/workflows/build.yml
 delete mode 100644 .travis.yml
 delete mode 100644 Dockerfile
 create mode 100644 build/README.md
 create mode 100755 build/build_builder
 create mode 100644 build/darwin.x86_64/Dockerfile
 create mode 100755 build/darwin.x86_64/build
 create mode 100644 build/darwin.x86_64/tag
 create mode 100644 build/linux.aarch64/Dockerfile
 create mode 100755 build/linux.aarch64/build
 create mode 100644 build/linux.aarch64/tag
 create mode 100644 build/linux.armv6hf/Dockerfile
 create mode 100755 build/linux.armv6hf/build
 create mode 100644 build/linux.armv6hf/tag
 create mode 100644 build/linux.x86_64/Dockerfile
 create mode 100755 build/linux.x86_64/build
 create mode 100644 build/linux.x86_64/tag
 create mode 100755 build/run_builder
 create mode 100644 build/windows.x86_64/Dockerfile
 create mode 100755 build/windows.x86_64/build
 create mode 100644 build/windows.x86_64/tag

BUG=chromium:1197113
TEST=stack test; spot check cros lint

Change-Id: I013f40250ade694ba416fa9c48cdeac0dd98370b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SC1008 Shell detection fails on "#!/usr/bin/env -S bash"

3 participants