For POSIXy but technically not POSIX / generic sh interpreter, try running <interpreter> -n <script> to perform a per-interpreter syntax check.
By the way, it is quite common for DevOps users to be writing scripts for shells that they do not have installed locally or in CI. For example, a mksh script will be unable to mksh -n <script> in most non-MirOS environments.
Ensure explicit mvdan/sh parsing continues to be used for generic "sh" scripts, in order to avoid accidentally parsing with a superset shell like a /bin/sh -> bash s{him,ymlink}.
Note that modern bash 4.2+ offers --posix flag. Combined with -n, this could double as another POSIX sh syntax validator, as long as bash is installed.
[x] Check in examples/imposter script self-describing as POSIX #!/bin/sh but in fact presenting sh-incompatible csh syntax.
[x] Record the syntax check flag for a variety of languages.
[x] Perform syntax validation prior to other POSIXy checks, to ensure that the rest of the warnings would, in fact, apply to such a script.
Syntax check flags:
the wider UNIX shell family (sh/bash/zsh/ksh/csh/tcsh/rc/fish/make/etc.): <interpreter> -n <script>
For POSIXy but technically not POSIX / generic sh interpreter, try running
<interpreter> -n <script>
to perform a per-interpreter syntax check.By the way, it is quite common for DevOps users to be writing scripts for shells that they do not have installed locally or in CI. For example, a
mksh
script will be unable tomksh -n <script>
in most non-MirOS environments.Ensure explicit mvdan/sh parsing continues to be used for generic "sh" scripts, in order to avoid accidentally parsing with a superset shell like a
/bin/sh -> bash
s{him,ymlink}.Note that modern bash 4.2+ offers
--posix
flag. Combined with-n
, this could double as another POSIX sh syntax validator, as long as bash is installed.examples/imposter
script self-describing as POSIX#!/bin/sh
but in fact presenting sh-incompatible csh syntax.Syntax check flags:
<interpreter> -n <script>
powershell -Command "Get-Command -syntax <script>"
<interpreter> -c <script>
<interpreter> -l <script>
python -m py_compile <script>
<interpreter> --lint -f <script>
gofmt -e <script>
The work involves expanding interpreter analysis, populating this field based on filenames when needed.