
Hi everyone Something useful I came across the other day: https://www.shellcheck.net/ finds bugs in your shell scripts. You can cabal, apt, dnf, pkg or brew install it locally right now. The above website lets you paste and analyze scripts, if you want to give it a spin. Cheers, Peter -- Peter Reutemann Dept. of Computer Science University of Waikato, Hamilton, NZ Mobile +64 22 190 2375 https://www.cs.waikato.ac.nz/~fracpete/ http://www.data-mining.co.nz/

On Wed, 4 Oct 2023 11:03:06 +1300, Peter Reutemann wrote:
Something useful I came across the other day:
https://www.shellcheck.net/ finds bugs in your shell scripts.
Just for fun, I tried this: collect_expand() { local -n arr="$2" arr=() coproc expander { find . -maxdepth 1 -name "$1" -print0; } # must ensure while-loop runs in this process while read -u ${expander[0]} -rd '' line; do arr[${#arr[*]}]="$line" done wait $expander_PID } # collect_expand #+ # Mainline #- test_filenames=('file 1.dat' $'file number\n2.dat' $'file\t3 dat') # test multiple spaces in a row and newlines, among any other odd # things you can think of! tmpdir=$(mktemp -d -p '' collect-work.XXXXXXXXXX) echo "tmpdir =" $(printf %q "$tmpdir") cd "$tmpdir" for f in "${test_filenames[@]}"; do echo "create" $(printf %q "$f") touch "$f" done collect_expand '*dat' found_filenames for f in "${found_filenames[@]}"; do echo "found" $(printf %q "$f") done cd rm -rfv "$tmpdir" and it came back with Line 9: while read -u ${expander[0]} -rd '' line; do ^-- SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: (apply this, apply all SC2086) while read -u "${expander[0]}" -rd '' line; do Line 12: wait $expander_PID ^-- SC2154 (warning): expander_PID is referenced but not assigned. ^-- SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: (apply this, apply all SC2086) wait "$expander_PID" Line 24: echo "tmpdir =" $(printf %q "$tmpdir") ^-- SC2046 (warning): Quote this to prevent word splitting. Line 26: cd "$tmpdir" ^-- SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails. Did you mean: (apply this, apply all SC2164) cd "$tmpdir" || exit Line 28: echo "create" $(printf %q "$f") ^-- SC2046 (warning): Quote this to prevent word splitting. Line 33: for f in "${found_filenames[@]}"; do ^-- SC2154 (warning): found_filenames is referenced but not assigned. Line 34: echo "found" $(printf %q "$f") ^-- SC2046 (warning): Quote this to prevent word splitting. Line 37: cd ^-- SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails. Did you mean: (apply this, apply all SC2164) cd || exit I would have to count every single one of those messages as spurious.
participants (2)
-
Lawrence D'Oliveiro
-
Peter Reutemann