[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251016214707.5c3d373b@pumpkin>
Date: Thu, 16 Oct 2025 21:47:07 +0100
From: David Laight <david.laight.linux@...il.com>
To: Kevin Locke <kevin@...inlocke.name>
Cc: Jonathan Corbet <corbet@....net>, Randy Dunlap <rdunlap@...radead.org>,
Thorsten Leemhuis <linux@...mhuis.info>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] tools: fix == bashism in kernel-chktaint
On Sat, 11 Oct 2025 15:04:26 -0600
Kevin Locke <kevin@...inlocke.name> wrote:
> When /bin/sh is a shell other than bash, invoking kernel-chktaint with
> at least one argument may produce error messages such as the following
> (produced by [dash] with argument 1024):
>
> ./kernel-chktaint: 22: [: 1024x: unexpected operator
> ./kernel-chktaint: 22: [: 1024x: unexpected operator
>
> This occurs because the == operator is not specified for [test in POSIX]
> and is not supported by all shells, as noted by shellcheck [SC3014].
>
> To fix the issue and avoid the error message, replace == with =.
>
> [dash]: https://git.kernel.org/pub/scm/utils/dash/dash.git
> [test in POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html
> [SC3014]: https://www.shellcheck.net/wiki/SC3014
>
> Signed-off-by: Kevin Locke <kevin@...inlocke.name>
> ---
> tools/debugging/kernel-chktaint | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/debugging/kernel-chktaint b/tools/debugging/kernel-chktaint
> index e7da0909d0970..051608a63d9f1 100755
> --- a/tools/debugging/kernel-chktaint
> +++ b/tools/debugging/kernel-chktaint
> @@ -19,7 +19,7 @@ EOF
> }
>
> if [ "$1"x != "x" ]; then
> - if [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then
> + if [ "$1"x = "--helpx" ] || [ "$1"x = "-hx" ] ; then
Ugg - one of the reasons for adding an x is to stop the string being treated as
an operator - but you need to to add at the front, not the end.
You don't need one to avoid an empty string - the quotes to that.
Although, IIRC, the posix standard requires the 3-operand expressions
be evaluated 'as expected' even if the first is (say) "-n".
ISTR that the 5-operand [ a = b -o c = d ] is also required to be parsed.
But, in any case, you can do:
if [ "x$1" = x--help -o "x$1" = x-h ]; then
David
> usage
> exit 1
> elif [ $1 -ge 0 ] 2>/dev/null ; then
Powered by blists - more mailing lists