mikshaw
Group: Members
Posts: 4856
Joined: July 2004 |
|
Posted: Sep. 29 2006,12:28 |
|
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.
-------------- http://www.tldp.org/LDP/intro-linux/html/index.html
|