Subject: [PATCH 3/4] checkbashisms: Allow stdin to be checked by accepting '-' as file name

From: Raphael Geissert <[email-masked]>
Date: Thu, 19 Apr 2012 23:19:48 -0500

---
 scripts/checkbashisms.pl |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index bc89d3b..8840d55 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -50,6 +50,11 @@ my ($opt_echo, $opt_force, $opt_extra, $opt_posix);
 my ($opt_help, $opt_version);
 my @filenames;
 
+# Detect if STDIN is a pipe
+if (scalar(@ARGV) == 0 && (-p STDIN or -f STDIN)) {
+    push(@ARGV, '-');
+}
+
 ##
 ## handle command-line options
 ##
@@ -69,16 +74,6 @@ if ($opt_version) { print $version; exit 0; }
 
 $opt_echo = 1 if $opt_posix;
 
-# Detect if STDIN is a pipe
-if (scalar(@ARGV) == 0 && (-p STDIN or -f STDIN)) {
-    my ($tmp_fh, $tmp_filename) = tempfile("chkbashisms_tmp.XXXX", TMPDIR => 1, UNLINK => 1);
-    while (my $line = <STDIN>) {
-        print $tmp_fh $line;
-    }
-    close($tmp_fh);
-    push(@ARGV, $tmp_filename);
-}
-
 my $status = 0;
 my $makefile = 0;
 my (%bashisms, %string_bashisms, %singlequote_bashisms);
@@ -90,8 +85,15 @@ foreach my $filename (@ARGV) {
     my $check_lines_count = -1;
 
     my $display_filename = $filename;
-    if ($filename =~ /chkbashisms_tmp\.....$/) {
-        $display_filename = "(stdin)";
+
+    if ($filename eq '-') {
+	my $tmp_fh;
+	($tmp_fh, $filename) = tempfile("chkbashisms_tmp.XXXX", TMPDIR => 1, UNLINK => 1);
+	while (my $line = <STDIN>) {
+	    print $tmp_fh $line;
+	}
+	close($tmp_fh);
+	$display_filename = "(stdin)";
     }
 
     if (!$opt_force) {
-- 
1.7.9.1