Skip to content

Instantly share code, notes, and snippets.

@koonix
Created September 10, 2022 20:57
Show Gist options
  • Save koonix/e04bc3f66e8cb704bf54456036fae444 to your computer and use it in GitHub Desktop.
Save koonix/e04bc3f66e8cb704bf54456036fae444 to your computer and use it in GitHub Desktop.
check #!/bin/sh-shebanged scripts in /usr/bin for dash-incompatible syntax using shellcheck.
#!/bin/sh
# check #!/bin/sh-shebanged scripts in /usr/bin for
# dash-incompatible syntax using shellcheck.
# config
outdir=~/bashisms
searchdir=/usr/bin
mkdir -p "$outdir" || exit 1
for file in "$searchdir"/*; do
[ -f "$file" ] && [ -r "$file" ] && sed -n '/^#!\/bin\/sh/q0;q1' "$file" || continue
shchmsg=$(shellcheck -s dash -i 2039,2169,2240,2279,$(seq -s, 3001 3060) "$file")
[ $? -eq 0 ] && continue
basename=${file##*/}
echo "$basename"
printf '%s\n' "$shchmsg" > "$outdir/$basename"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment