4371 shaares
bash -n
is a basic but useful builtin syntax linter.
If you do not use the pre-commit
Python command & hook manager (check it out, it's great!), you can define a git
pre-commit hook "manually" by putting the following in a file at .git/hooks/pre-commit
:
#!/bin/sh
# Redirect output to stderr:
exec 1>&2
echo "Executing bash native syntax linter on all modified .sh files:"
if ! git diff --cached --name-only --diff-filter=AM HEAD | grep '.sh$' | xargs -n 1 bash -n
then
echo "Error : syntax issues were detected"
exit 1
fi