Fix: Replace bashism with POSIX-compliant pattern matching

Replaced the bash specific conditional [[ $base" == .* ]] with a case statement.

Not sure why my first commit ran on my machine without error.
This commit is contained in:
Peter MacKenzie-Basaraba 2025-04-06 11:24:15 -06:00 committed by GitHub
parent 7f2211a921
commit 71500c1699
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,10 +10,9 @@
[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1
base="$(basename "$1")"
if [[ "$base" == .* ]]; then
ls_opt="ls -a"
else
ls_opt="ls"
fi
case "$base" in
.*) ls_opt="ls -a" ;;
*) ls_opt="ls" ;;
esac
$ls_opt "$PWD" | awk -v BASE="$base" 'BEGIN { lines = ""; m = 0; } { if ($0 == BASE) { m = 1; } } { if (!m) { if (lines) { lines = lines"\n"; } lines = lines""$0; } else { print $0; } } END { print lines; }'