Skip to content

Instantly share code, notes, and snippets.

@angristan
Created February 9, 2019 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angristan/39b3d4a4d9d7c82d1325bb216bac17e0 to your computer and use it in GitHub Desktop.
Save angristan/39b3d4a4d9d7c82d1325bb216bac17e0 to your computer and use it in GitHub Desktop.
Lint shell executables with shellcheck
#!/bin/bash
set -e
set -o pipefail
ERRORS=()
# find all executables and run `shellcheck`
for f in $(find . -type f -not -iwholename '*.git*' | sort -u); do
if file "$f" | grep --quiet shell; then
{
shellcheck "$f" && echo "[OK]: sucessfully linted $f"
} || {
# add to errors
ERRORS+=("$f")
}
fi
done
if [ ${#ERRORS[@]} -eq 0 ]; then
echo "No errors, hooray"
else
echo "These files failed shellcheck: ${ERRORS[*]}"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment