Shellcheck: Can ShellCheck check if a script is POSIX-compliant?

Created on 20 Mar 2019  Â·  2Comments  Â·  Source: koalaman/shellcheck

Example 1 – Using paste with no file-name, required for macOS

printf '%s\n' foo bar baz | paste -s -d ','

Example 2 – Using realpath which is GNU-only

realpath file.txt

Most helpful comment

paste is also an external command. Shellcheck doesn't check for the presence/absence of _any_ external commands or flags. This will pass just fine:

aaaaaa foo bar | paste --nonexistant-flag

However, Shellcheck will warn you on _builtins_ which exist in other shells (e.g.: typeset) with SC2039.

All 2 comments

Shellcheck will not let you check your script for POSIX compliance directly, as far as I know at least. However, shellcheck does let you explicitly check for compliance with the 'dash' shell, which aims to be POSIX compliant, which may be 'good enough' for your purpose.

shellcheck --shell=dash ./myscript.sh

However, this may not get what you are looking for: 'realpath' is a GNU (coreutils) external command, and not any shell built-in, so it will work with any shell (as long as the external command is available).

paste is also an external command. Shellcheck doesn't check for the presence/absence of _any_ external commands or flags. This will pass just fine:

aaaaaa foo bar | paste --nonexistant-flag

However, Shellcheck will warn you on _builtins_ which exist in other shells (e.g.: typeset) with SC2039.

Was this page helpful?
0 / 5 - 0 ratings