1
0
mirror of synced 2026-04-24 19:50:09 +00:00

Harden this test.

Read and test only the shebang, not the whole file, +typos.

Ignore empty files.
This commit is contained in:
Stéphane Jourdois
2010-07-18 16:05:57 +02:00
committed by Stéphane Jourdois
parent 3b26e3f54f
commit 19d84a3d9e

View File

@@ -34,26 +34,28 @@ sub checkFile
# We don't care about directories
return if ( ! -f $file );
# Finally mercurial files are fine.
return if ( $file =~ /\.(hg|git)\// );
# We don't care about empty files
return unless -s $file;
# Finally mercurial/git files are fine.
return if ( $file =~ /^\.\/\.(hg|git)\// );
# See if it is a shell script.
my $isShell = 0;
# Read the file.
# Read the shebang
open( INPUT, "<", $file );
foreach my $line ( <INPUT> )
{
if ( ( $line =~ /\/bin\/sh/ ) ||
( $line =~ /\/bin\/bash/ ) )
{
$isShell = 1;
}
}
my $line = <INPUT>;
close( INPUT );
# Check if it is really a shell file
if ( $line =~ /^#! ?\/bin\/(ba)?sh/ )
{
$isShell = 1;
}
#
# Return if it wasn't a perl file.
# Return if it wasn't a shell file.
#
return if ( ! $isShell );