[PATCH] Warn about bash scripts that do not have any bashisms

Paul Wise pabs at debian.org
Thu Nov 22 05:52:30 UTC 2012


---
 scripts/checkbashisms.1  |    3 +++
 scripts/checkbashisms.pl |   19 +++++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/scripts/checkbashisms.1 b/scripts/checkbashisms.1
index a835d3d..03d403e 100644
--- a/scripts/checkbashisms.1
+++ b/scripts/checkbashisms.1
@@ -57,6 +57,9 @@ A possible bashism was detected.
 2
 A file was skipped for some reason, for example, because it was
 unreadable or not found.  The warning message will give details.
+.TP
+4
+No bashisms were detected in a bash script.
 .SH "SEE ALSO"
 .BR lintian (1).
 .SH AUTHOR
diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index 6180d54..133ea60 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -33,7 +33,7 @@ Usage: $progname [-n] [-f] [-x] script ...
    or: $progname --help
    or: $progname --version
 This script performs basic checks for the presence of bashisms
-in /bin/sh scripts.
+in /bin/sh scripts and the lack of bashisms in /bin/bash ones.
 EOF
 
 my $version = <<"EOF";
@@ -74,6 +74,8 @@ if ($opt_version) { print $version; exit 0; }
 
 $opt_echo = 1 if $opt_posix;
 
+my $mode = 0;
+my $issues = 0;
 my $status = 0;
 my $makefile = 0;
 my (%bashisms, %string_bashisms, %singlequote_bashisms);
@@ -116,6 +118,8 @@ foreach my $filename (@ARGV) {
 	next;
     }
 
+    $issues = 0;
+    $mode = 0;
     my $cat_string = "";
     my $cat_indented = 0;
     my $quote_string = "";
@@ -143,9 +147,7 @@ foreach my $filename (@ARGV) {
 		next if $opt_force;
 
 		if ($interpreter =~ m,/bash$,) {
-		    warn "script $display_filename is already a bash script; skipping\n";
-		    $status |= 2;
-		    last;  # end this file
+		    $mode = 1;
 		}
 		elsif ($interpreter !~ m,/(sh|posh)$,) {
 ### ksh/zsh?
@@ -476,6 +478,11 @@ foreach my $filename (@ARGV) {
 	if ($buffered_line ne '');
 
     close C;
+
+    if( $mode && !$issues ){
+	warn "could not find any possible bashisms in bash script $filename\n";
+	$status |= 4;
+    }
 }
 
 exit $status;
@@ -483,8 +490,8 @@ exit $status;
 sub output_explanation {
     my ($filename, $line, $explanation) = @_;
 
-    warn "possible bashism in $filename line $. ($explanation):\n$line\n";
-    $status |= 1;
+    warn "possible bashism in $filename line $. ($explanation):\n$line\n" unless $mode;
+    $mode ? $issues = 1 : $status |= 1;
 }
 
 # Returns non-zero if the given file is not actually a shell script,
-- 
1.7.10.4




More information about the devscripts-devel mailing list