2 # sh.test - check for some nonportable or dubious or undesired shell
3 # constructs in shell scripts.
5 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010 Free
6 # Software Foundation, Inc.
7 # Written by Gary V. Vaughan, 2003
9 # This file is part of GNU Libtool.
11 # GNU Libtool is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation; either version 2 of
14 # the License, or (at your option) any later version.
16 # GNU Libtool is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with GNU Libtool; see the file COPYING. If not, a copy
23 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
24 # or obtained by writing to the Free Software Foundation, Inc.,
25 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 . tests/defs || exit 1
30 # Check all the "portable" shell scripts.
33 # Check for bad binary operators.
34 if $EGREP -n -e 'if[ ]+["'\'']?\$[^ ]+[ ]+(=|-[lg][te]|-eq|-ne)' $scripts; then
35 echo "use \`if test \$something =' instead of \`if \$something ='"
39 # Check for bad unary operators.
40 if $EGREP -n -e 'if[ ]+-' $scripts; then
41 echo "use \`if test -X' instead of \`if -X'"
45 # Check for using `[' instead of `test'.
46 if $EGREP -n -e 'if[ ]+\[' $scripts; then
47 echo "use \`if test' instead of \`if ['"
51 # Check for using test X... instead of test "X...
52 if $EGREP -n -e 'test[ ]+(![ ])?(-.[ ]+)?X' $scripts; then
53 echo "use \`test \"X...\"' instead of \`test X'"
57 # Check for using test $... instead of test "$...
58 if $EGREP -n -e 'test[ ]+(![ ])?(-.[ ]+)?X?\$' $scripts; then
59 echo "use \`test \"\$...\"' instead of \`test \$'"
64 if $EGREP -n -e 'test[ ]+(![ ])?-e' $scripts; then
65 echo "use \`test -f' instead of \`test -e'"
69 # Check for uses of Xsed without corresponding echo "X
70 if $EGREP -n -e '\$Xsed' $scripts | $EGREP -v -n -e '\$ECHO \\*"X'; then
71 echo "occurrences of \`\$Xsed\' without \`echo \"X\' on the same line"
75 # Check for quotes within backquotes within quotes "`"bar"`"
76 if $EGREP -n -e '"[^`"]*`[^"`]*"[^"`]*".*`[^`"]*"' $scripts | \
77 $EGREP -v "### testsuite: skip nested quoting test$"; then
78 echo "nested quotes are dangerous"
82 # Check for using set -- instead of set dummy
83 if $EGREP -n -e 'set[ ]+--[ ]+' $scripts; then
84 echo "use \`set dummy ...' instead of \`set -- ...'"
88 # Check for using shift after set dummy (same or following line).
93 /set.*dummy.*;.*shift/d
97 }' "$s" | $EGREP .; then
98 echo "use \`shift' after \`set dummy' in $s"
103 # Check for opening brace on next line in shell function definition.
104 # redirect stderr so we also barf when sed issues diagnostics.
110 /^func_[^ ]* ()\n{$/d
112 }' "$s" 2>&1 | $EGREP .; then
113 echo "Function definitions should look like this in $s:
122 # Check for correct usage of $cc_basename.
123 # redirect stderr so we also barf when sed issues diagnostics.
124 for s in "$m4dir/libtool.m4"
126 if $SED -n '/case \$cc_basename in/,/esac/ {
127 /^[ ]*[a-zA-Z][a-zA-Z0-9+]*[^*][ ]*)/p
128 }' $s 2>&1 | $EGREP .; then
129 echo "\$cc_basename matches should include a trailing \`*' in $s."