Bug#835498: checkbashisms treats 'command' incorrectly

Eero Vuojolahti eero at vuojolahti.com
Fri Aug 26 10:47:10 UTC 2016


Package: devscripts
Version: 2.16.7

contents of test.sh:
#!/bin/sh
command -v ls
command -V ls
command -p -v -a ls
command -p -a -v ls
command -pa ls
command -ap ls
command -p -a ls
command -pV -a ls
exit 0

Output from 'checkbashisms test.sh':
possible bashism in test.sh line 2 ('command' with option other than -p):
command -v ls
possible bashism in test.sh line 3 ('command' with option other than -p):
command -V ls


Firstly, the script didn't recognize invalid option -a, which appears on 
several lines.

Secondly, there are no optional flags listed in the 2008/2013 version of 
the 'command' specification. In the older (2004) standard, the |-v| and 
|-V| options were part of the 'user portability' subset, not part of the 
core. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html

Here's a diff that fixes the found issues.
diff -u devscripts/a/checkbashisms devscripts/b/checkbashisms
--- devscripts/a/checkbashisms    2016-08-22 07:01:48.000000000 +0300
+++ devscripts/b/checkbashisms    2016-08-26 13:04:44.385760367 +0300
@@ -644,7 +644,7 @@
      qr';;?&' =>  q<;;& and ;& special case operators>,
      $LEADIN . qr'jobs\s' =>  q<jobs>,
  #    $LEADIN . qr'jobs\s+-[^lp]\s' =>  q<'jobs' with option other than 
-l or -p>,
-    $LEADIN . qr'command\s+-[^p]\s' =>  q<'command' with option other 
than -p>,
+    $LEADIN . qr'command\s+(-[pvV]+\s+)*-[pvV]*[^pvV\s]+[pvV]*\s' =>  
q<'command' with option other than -p, -v or -V>,
      $LEADIN . qr'setvar\s' =>  q<setvar 'foo' 'bar' should be eval 
'foo="'"$bar"'"'>,
      $LEADIN . qr'trap\s+["\']?.*["\']?\s+.*(?:ERR|DEBUG|RETURN)' => 
q<trap with ERR|DEBUG|RETURN>,
      $LEADIN . qr'(?:exit|return)\s+-\d' => q<exit|return with negative 
status code>,

Output from the modified script:
checkbashisms test.sh
possible bashism in test.sh line 4 ('command' with option other than -p, 
-v or -V):
command -p -v -a ls
possible bashism in test.sh line 5 ('command' with option other than -p, 
-v or -V):
command -p -a -v ls
possible bashism in test.sh line 6 ('command' with option other than -p, 
-v or -V):
command -pa ls
possible bashism in test.sh line 7 ('command' with option other than -p, 
-v or -V):
command -ap ls
possible bashism in test.sh line 8 ('command' with option other than -p, 
-v or -V):
command -p -a ls
possible bashism in test.sh line 9 ('command' with option other than -p, 
-v or -V):
command -pV -a ls



More information about the devscripts-devel mailing list