From: Lewis Not on 22 Jul 2010 12:11 Kenny McCormack <gazelle(a)shell.xmission.com> wrote: >>if [ $last_seen -gt 0 ] && [ $last_seen -lt $toolate ] ; then > >Why? 1) cross-platform compatibility 2) readability Excellent example, though I would recommend adding quotes, for best practices, error checking and developing good coding habits, whether strictly necessary or not: if [ "$last_seen" -gt 0 ] && [ "$last_seen" -lt "$toolate" ]; then Lew
From: Chris F.A. Johnson on 22 Jul 2010 19:06 On 2010-07-22, Lewis Not wrote: > Kenny McCormack <gazelle(a)shell.xmission.com> wrote: >>>if [ $last_seen -gt 0 ] && [ $last_seen -lt $toolate ] ; then >> >>Why? > > 1) cross-platform compatibility > > 2) readability > > Excellent example, though I would recommend adding quotes, for best > practices, error checking and developing good coding habits, whether > strictly necessary or not: > > if [ "$last_seen" -gt 0 ] && [ "$last_seen" -lt "$toolate" ]; then I generally don't quote variables in numeric comparisons. If they don't contain integers, that is a programming error that needs to be fixed. -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
From: Seebs on 22 Jul 2010 20:51 On 2010-07-22, Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote: > I generally don't quote variables in numeric comparisons. If they > don't contain integers, that is a programming error that needs to > be fixed. But consider the quality of the diagnostic messages you get from such an error... -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Chris F.A. Johnson on 23 Jul 2010 13:25 On 2010-07-23, Seebs wrote: > On 2010-07-22, Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote: >> I generally don't quote variables in numeric comparisons. If they >> don't contain integers, that is a programming error that needs to >> be fixed. > > But consider the quality of the diagnostic messages you get from > such an error... You have a point, but either message would be enough to tell me the problem. (Though I don't think I've ever seen the error; if I am testing an integer, it's because I have already assigned an integer to that variable.) -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
First
|
Prev
|
Pages: 1 2 3 4 5 6 Prev: modify all makefiles in a directory tree Next: How do I get my IP and put it in a file? |