koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.11k stars 1.77k forks source link

In POSIX sh, rmdir flags besides -p are undefined #1455

Open contivero opened 5 years ago

contivero commented 5 years ago

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

#!/bin/sh
rmdir --parent /a/b/c

Here's what shellcheck currently says:

No issues detected!

Here's what I wanted or expected to see:

"In POSIX sh, rmdir flags besides -p are undefined"

The only acceptable flag for rmdir under POSIX sh is -p (see spec), --parent is a GNU synonym for -p not defined by POSIX. There are other flags defined by GNU's rmdir (such as --ignore-fail-on-non-empty) which are also not POSIX.

contivero commented 5 years ago

After opening this and uploading a fix to my fork, I realized it might not be the appropriate way (you can check it here). I approched it as the other similar fixes I did, but this one is not technically a bashism (GNUism?), so I'm not sure if I should leave it inside ShellSupport.hs, or if I should move it to the Commands.hs file.

koalaman commented 5 years ago

Like you say, bad flags to export, ulimit and other builtins are a bashism or shell support issue, while this is a more general userland issue. ShellCheck is currently only aware of which shell you're targeting, it doesn't know which userland.

The shell and userland are not necessarily connected:

There's not currently any support for trying to check whether e.g. a GNU/Linux script will run on macOS. This would be nice and has been briefly discussed a few times before (e.g. #674), but it's not currently supported and there's quite a few details to be worked out.

contivero commented 5 years ago

I'll focus on builtins then. You may close this, or leave it open in case it is eventually supported, however you see fit. Thanks for the detailed explanation! 🙂