Created
August 8, 2025 22:43
-
-
Save gnanet/2b213ea64e929a536a3df9114c93f48d to your computer and use it in GitHub Desktop.
shellcheck - bashlint; with install on-demand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # touch /usr/local/bin/shell-lint && chmod +x /usr/local/bin/shell-lint && nano /usr/local/bin/shell-lint | |
| # | |
| # ln -s /usr/local/bin/shell-lint /usr/local/bin/bashlint | |
| # | |
| if [ ! -x /usr/local/bin/shellcheck ]; then | |
| wget https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz -O /usr/local/src/shellcheck-v0.11.0.linux.x86_64.tar.xz | |
| if [ -f /usr/local/src/shellcheck-v0.11.0.linux.x86_64.tar.xz ]; then | |
| tar xJf /usr/local/src/shellcheck-v0.11.0.linux.x86_64.tar.xz -C /usr/local/bin --exclude='*.txt' --strip-components=1 | |
| fi | |
| fi | |
| LINT_SEVERITY=warning | |
| # LINT_SEVERITY=error | |
| # -e SC1083,SC2012,SC2028,SC2086,SC2162,SC2181 | |
| # -e SC1083,SC2012,SC2028,SC2086,SC2162,SC2181 | |
| if [ $1 ] && [ -f $1 ]; then | |
| #shellcheck --norc -Cnever -W 0 -S${LINT_SEVERITY} -s bash $1 | |
| # shellcheck --norc -Cnever -W 0 -S${LINT_SEVERITY} -s bash $1 | grep -E " SC[^\ ]+" | sed -e "s|^.* SC|SC|g" | sort | uniq | |
| while read sccode; do | |
| shellcheck --norc -Cnever -W 0 -S${LINT_SEVERITY} -s bash $1 | grep -E " SC[^\ ]+" | sed -e "s|^.* SC|SC|g" | sort | uniq | grep "${sccode}" | sed -e "s|^${sccode}| ${sccode}|g" | |
| shellcheck --norc -i ${sccode} -Cnever -W 0 -S${LINT_SEVERITY} -s bash $1 | grep -B2 "${sccode}" | grep " line " | sed -e "s|In ${1} | |g" | |
| done < <(shellcheck --norc -Cnever -W 0 -S${LINT_SEVERITY} -s bash $1 | grep -E " SC[^\ ]+" | sed -e "s|^.* SC|SC|g" | sort | uniq | awk {' print $1 '}) | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment