Message ID | 20240618090641.359008-1-pvorel@suse.cz |
---|---|
State | New |
Headers | show |
Series | [1/2] tools: kernel-chktaint: Fix bashism, simplify code | expand |
On 18.06.24 11:06, Petr Vorel wrote: > '==' is bashism, '=' needs to be used for comparison. > With this fix script can work on systems where the default shell is > dash, busybox ash or any other strictly POSIX compatible shell. > > While at it, also improve: > * remove "x" in the comparison (not needed for decades) > * use $# for checking number of arguments > * cleanup whitespace > > Fixes: 4ab5a5d2a4a22 ("tools: add a kernel-chktaint to tools/debugging") > Signed-off-by: Petr Vorel <pvorel@suse.cz> Acked-by: Thorsten Leemhuis <linux@leemhuis.info> Ciao, Thorsten
On 6/18/24 2:06 AM, Petr Vorel wrote: > '==' is bashism, '=' needs to be used for comparison. > With this fix script can work on systems where the default shell is > dash, busybox ash or any other strictly POSIX compatible shell. > > While at it, also improve: > * remove "x" in the comparison (not needed for decades) > * use $# for checking number of arguments > * cleanup whitespace > > Fixes: 4ab5a5d2a4a22 ("tools: add a kernel-chktaint to tools/debugging") > Signed-off-by: Petr Vorel <pvorel@suse.cz> Acked-by: Randy Dunlap <rdunlap@infradead.org> Thanks. > --- > tools/debugging/kernel-chktaint | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/tools/debugging/kernel-chktaint b/tools/debugging/kernel-chktaint > index 279be06332be9..adbb1d621ccd4 100755 > --- a/tools/debugging/kernel-chktaint > +++ b/tools/debugging/kernel-chktaint > @@ -18,11 +18,11 @@ retrieved from /proc/sys/kernel/tainted on another system. > EOF > } > > -if [ "$1"x != "x" ]; then > - if [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then > +if [ $# -gt 0 ]; then > + if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then > usage > exit 1 > - elif [ $1 -ge 0 ] 2>/dev/null ; then > + elif [ $1 -ge 0 ] 2>/dev/null; then > taint=$1 > else > echo "Error: Parameter '$1' not a positive integer. Aborting." >&2
diff --git a/tools/debugging/kernel-chktaint b/tools/debugging/kernel-chktaint index 279be06332be9..adbb1d621ccd4 100755 --- a/tools/debugging/kernel-chktaint +++ b/tools/debugging/kernel-chktaint @@ -18,11 +18,11 @@ retrieved from /proc/sys/kernel/tainted on another system. EOF } -if [ "$1"x != "x" ]; then - if [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then +if [ $# -gt 0 ]; then + if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then usage exit 1 - elif [ $1 -ge 0 ] 2>/dev/null ; then + elif [ $1 -ge 0 ] 2>/dev/null; then taint=$1 else echo "Error: Parameter '$1' not a positive integer. Aborting." >&2
'==' is bashism, '=' needs to be used for comparison. With this fix script can work on systems where the default shell is dash, busybox ash or any other strictly POSIX compatible shell. While at it, also improve: * remove "x" in the comparison (not needed for decades) * use $# for checking number of arguments * cleanup whitespace Fixes: 4ab5a5d2a4a22 ("tools: add a kernel-chktaint to tools/debugging") Signed-off-by: Petr Vorel <pvorel@suse.cz> --- tools/debugging/kernel-chktaint | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)