4 ms·
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 diffi
by ixmatus 13y ago
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.
- lutusp 13y ago> Huh, could you elaborate? 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.
- ixmatus 13y agoThanks for the input, I also corrected attribution of the script, thanks for pointing that out :)
- lutusp 13y agoYou'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. :)