The unindented, unreadable shell script listing at the end of the linked blog entry shows why the absence of program-list indentation capability destroys its meaning more quickly than "rm ~".
Huh, could you elaborate? I found the script written by someone else but decided to run it through a beautifier; you're right that no indentation makes it difficult to understand.
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.
You're welcome, good practice. The listing still isn't indented correctly -- just comment out all cases of ";;", run the beautifier, then uncomment them.
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. :)
6 comments
[ 2.7 ms ] story [ 22.7 ms ] threadA 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:
> 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. :)