koalaman / shellcheck

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

find -printf is not defined in POSIX #2406

Open slycordinator opened 2 years ago

slycordinator commented 2 years ago

Shellcheck does not warn when one is using "find" with the GNU "-fprint" option.

For bugs

For new checks and feature suggestions

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


#!/bin/sh
find . -type f -printf '%f\n'

Here's what shellcheck currently says:

[nothing]

Here's what I wanted or expected to see:

In POSIX sh, find -printf is undefined

When I run the command above in dash/bash, I get a listing of all files each on their own line as expected When I run it in busybox, I get "find: unrecognized: -printf"

https://pubs.opengroup.org/onlinepubs/007904975/utilities/find.html

brother commented 2 years ago

find is an external command.

slycordinator commented 2 years ago

I'm aware that find is an external command.

AFAIK, shellcheck checks for arguments to some external commands to warn if they are not posix compliant.

But I could be wrong about this. Either way, it would be a nice addition to warn that the argument given is not portable.

TinCanTech commented 2 years ago

The comment was: "find is an external command" .. not shellcheck

In what way do you mean not portable ?

slycordinator commented 2 years ago

I mean portable as in being easily moved from one system to another.

A script that uses "find -printf" will run perfectly fine on most Linux distros, fail if you move it to one that uses posix utilities, and similarly fail if you were to run it on many other Unixes.

On Fri, Dec 17, 2021, 12:37 AM TinCanTech @.***> wrote:

The comment was: "find is an external command" .. not shellcheck

In what way do you mean not portable ?

— Reply to this email directly, view it on GitHub https://github.com/koalaman/shellcheck/issues/2406#issuecomment-995931095, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQN7DTIABVXZWSVTVT2IJSTURIBTDANCNFSM5JTACSVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>