Jeah. I thought that too, but manuals never use then after elif. But well. Let's try it anyway. =)Well it worked anyway. Thanks. In addition to that, you might consider cutting down on your "if" statements, simply to make maintenance easier and keep it more readable.
If you're testing multiple (more than 2) values of a single variable I'd say "case" is much more appropriate. This way all of your results of the $1 check can be put in an orderly manner, you won't have a huge amount of overlapping ifs and fis and thens to confuse, and then *I'll* be able to read it
Anyway, that's just opinion, but here's what I'd do....
Code Sample
if [ -n "$1" ]; then case "$1" in mount) stuff for mount ;; umount) stuff for umount ;; *) stuff for every other $1 result ;; esac fi
Also, you don't have to test both -z $1 and -n $1. If -z $1 is false and doesn't exit, you know -n $1 will be true. If a case with -n $1 is the only code, including -z $1 is just redundant.Heh, nice review mikshaw.
I'll just add that you probably won't need to use 'then' after 'else' if you're just doing 1 (self-enclosed) command.I dunno what the fuss is all about,
I just have a list of mount cmds in my script, don't care about any error msgs, just ignore them.Next Page...
original here.