Skip to content

Instantly share code, notes, and snippets.

@jehiah
Created September 15, 2012 02:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jehiah/3726075 to your computer and use it in GitHub Desktop.
Save jehiah/3726075 to your computer and use it in GitHub Desktop.
bash shell script syntax checking
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment