public
Last active

bash shell script syntax checking

  • Download Gist
test_shell_scripts.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/bin/sh
#
# This is a script to run syntax check (via `sh -n $filename`) but it
# supports recursive checking and --quiet
 
QUIET=0
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
--quiet)
QUIET=1
;;
esac
shift
done
 
find . -name '*.sh' > /tmp/shell_script_list
failed_shell_scripts=""
while read filename ; do
OUTPUT=`sh -n "$filename" 2>&1 >/dev/null 2>&1`
if [ "$?" == "0" ]; then
echo -n "."
else
if [ "$QUIET" == "1" ]; then
echo -n "F"
else
echo "F"
echo "$filename"
sh -n "$filename"
echo ""
fi
fi
done </tmp/shell_script_list
echo ""
if [ "$QUIET" == "0" ]; then
echo "test with \"sh -n \$file\""
fi

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.