aboutsummaryrefslogtreecommitdiff
path: root/contrib/pre-commit/bash_syntax
blob: 7e014e89e8b30b653f5edba07c858780f63989ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

function test_file {
    file="${1}"
    head -n 1 "${file}" | grep 'bash' | grep '^#!/' > /dev/null
    if [ "$?" -eq 0 ] ; then
        set -e
        bash -n "${file}"
        set +e
    fi
}

case "${1}" in
    --about )
        echo "Check bash shell scripts for syntax errors."
        ;;
    * )
        for file in `git diff-index --cached --name-only HEAD` ; do
            test_file "${file}"
        done
        ;;
esac