Rm is dangerous
parnell.io
parnell.io
A shell script's structure is lost without indentation, making it necessary to very carefully sort out its meaning. BTW your corrected script still doesn't have the indentation done properly -- here it is, correctly indented:
#!/bin/bash
# filename: trash-rm
shopt -s extglob
recursive=1
declare -a cmd
((i = 0))
for f in "$@"
do
case "$f" in
(-*([fiIv])r*([fiIv])|-*([fiIv])R*([fiIv]))
tmp="${f//[rR]/}"
if [ -n "$tmp" ]
then
#echo "\$tmp == $tmp"
cmd[$i]="$tmp"
((i++))
fi
recursive=0 ;;
(--recursive) recursive=0 ;;
(*)
if [ $recursive != 0 -a -d "$f" ]
then
echo "skipping directory: $f"
continue
else
cmd[$i]="$f"
((i++))
fi ;;
esac
done
trash-put "${cmd[@]}"
> I found the script written by someone else but decided to run it through a beautifier ...The beautifier your chose failed to indent consistently -- note that the original doesn't consistently indent the block between "case" and "esac", among other errors.
This might sound like something trivial and after the fact, but beautifying can reveal logical errors that can escape the eye in a program listing that lacks indentation.
To force your beautifier to behave, temporarily comment out all cases of ";;", run the beautifier, then uncomment them.
> I found the script written by someone else ...
What? Your article doesn't say that. Please take some advice and give proper attribution for code that you include in an article but didn't write.
I confess to being rather spoiled by code beautifiers -- it's gotten so I can't follow the logic of a program that isn't indented correctly. :)