[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[checks/scripts] checkbashsims update



Hi,

Please find attached a patch which updates checks/scripts in line with
recent changes to checkbashisms.

The changes are:

- Fix the $(< foo) test to not trigger on $(< foo grep bar) and similar
constructs. (i.e. there should only be a single word between < and ) in
order to trigger.)

- Add a test for <& and >& redirecting to a file (rather than - or a
file descriptor)

- Add tests for $(OS|MACH)TYPE, $HOST(TYPE|NAME), $DIRSTACK, $EUID

- Add a test for bash's herestring (<<<)

- Modify the heredoc detection code to not trigger on herestrings, so
that they can be caught by the previous test

Hopefully all the changes make sense, but if not please let me know.

Adam
--- scripts.orig	2008-02-24 14:03:47.000000000 +0000
+++ scripts	2008-02-24 14:40:12.000000000 +0000
@@ -541,8 +541,12 @@
 		  '\$\{\#?\w+\[[0-9\*\@]+\]\}',# bash arrays, ${name[0|*|@]}
 		  '\$\{!\w+[\@*]\}',	       # ${!prefix[*|@]}
 		  '\$\{!\w+\}',		       # ${!name}
-		  '(\$\(|\`)\s*\<\s*\S.+(\)|\`)', # $(\< foo) should be $(cat foo)
+		  '(\$\(|\`)\s*\<\s*\S+\s*(\)|\`)' # $(\< foo) should be $(cat foo)
 		  '\$RANDOM\b',		       # $RANDOM
+		  '\$(OS|MACH)TYPE\b',	       # $(OS|MACH)TYPE
+		  '\$HOST(TYPE|NAME)\b',       # $HOST(TYPE|NAME)
+		  '\$DIRSTACK\b',	       # $DIRSTACK
+		  '\$EUID\b',		       # $EUID should be "id -u"
 		);
 		my @bashism_regexs = (
 		  'function \w+\(\s*\)',       # function is useless
@@ -556,6 +560,7 @@
 		  '(?:^|\s+)kill\s+-[^sl]\w*', # kill -[0-9] or -[A-Z]
 		  '(?:^|\s+)trap\s+["\']?.*["\']?\s+.*[1-9]', # trap with signal numbers
 		  '\&>',		       # cshism
+		  '(<\&|>\&)\s*(-[^\s;|]|\d+[^\s;|]|[^-\d\s;|])', # should be >word 2>&1
 		  '\[\[(?!:)',		       # alternative test command
 		  '(?:^|\s+)select\s+\w+',     # 'select' is not POSIX
 		  '\$\(\([A-Za-z]',	       # cnt=$((cnt + 1)) does not work in dash
@@ -564,6 +569,7 @@
 		  '(?:^|\s+)let\s',	       # let ...
 		  '(?<![\$\(])\(\(.*\)\)',     # '((' should be '$(('
 		  '(\[|test)\s+-a',	       # test with unary -a (should be -e)
+		  '<<<',                       # <<< here string
 		);
 
 		# since this test is ugly, I have to do it by itself
@@ -610,7 +616,7 @@
 
 		# Only look for the beginning of a heredoc here, after we've
 		# stripped out quoted material, to avoid false positives.
-		if (m/\<\<\s*[\'\"]?(\w+)[\'\"]?/) {
+		if (m/(^|[^\<])\<\<\s*[\'\"]?(\w+)[\'\"]?/) {
 		    $cat_string = $1;
 		}
 	    }

Reply to: