From: Robert Latest on 12 Jul 2010 14:00 Hello all, quoting the "sh" manpage: test expression [ expression ] The test utility evaluates the expression and, if it evaluates to true, returns a zero (true) exit status; otherwise it returns 1 (false). If there is no expression, test also returns 1 (false). All operators and flags are separate arguments to the test util‐ ity. The following primaries are used to construct expression: [...] expression1 -a expression2 True if both expression1 and expression2 are true. expression1 -o expression2 True if either expression1 or expression2 are true. (expression) True if expression is true. I've written a script that contains this line: if [ ($last_seen -gt 0) -a ($last_seen -lt $toolate) ] ; then # whatever fi It throws this syntax error: test.sh: 23: Syntax error: word unexpected (expecting ")") Why? robert
From: Lew Pitcher on 12 Jul 2010 14:21 On July 12, 2010 14:00, in comp.unix.shell, boblatest(a)yahoo.com wrote: > > Hello all, > quoting the "sh" manpage: > > test expression > > [ expression ] > The test utility evaluates the expression and, if it evaluates > to true, returns a zero (true) exit status; otherwise it > returns 1 > (false). If there is no expression, test also returns 1 > (false). > > All operators and flags are separate arguments to the test > utilâ ity. > > The following primaries are used to construct expression: > > [...] > > > expression1 -a expression2 > True if both expression1 and expression2 are > true. > > expression1 -o expression2 > True if either expression1 or expression2 are > true. > > (expression) True if expression is true. > > > I've written a script that contains this line: > > if [ ($last_seen -gt 0) -a ($last_seen -lt $toolate) ] ; then > # whatever > fi > > It throws this syntax error: > > test.sh: 23: Syntax error: word unexpected (expecting ")") > > Why? Remember that the brackets need to be separate tokens Instead of if [ ($last_seen -gt 0) -a ($last_seen -lt $toolate) ] ; then try if [ ( $last_seen -gt 0 ) -a ( $last_seen -lt $toolate ) ] ; then -- Lew Pitcher Master Codewright & JOAT-in-training | Registered Linux User #112576 Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/ ---------- Slackware - Because I know what I'm doing. ------
From: Chris F.A. Johnson on 12 Jul 2010 14:33 On 2010-07-12, Robert Latest wrote: > > Hello all, > quoting the "sh" manpage: > > test expression > > [ expression ] > The test utility evaluates the expression and, if it evaluates to > true, returns a zero (true) exit status; otherwise it returns 1 > (false). If there is no expression, test also returns 1 (false). > > All operators and flags are separate arguments to the test util??? > ity. > > The following primaries are used to construct expression: > > [...] > > > expression1 -a expression2 > True if both expression1 and expression2 are true. > > expression1 -o expression2 > True if either expression1 or expression2 are true. > > (expression) True if expression is true. > > > I've written a script that contains this line: > > if [ ($last_seen -gt 0) -a ($last_seen -lt $toolate) ] ; then > # whatever > fi Avoid -a and -o; use && and ||: if [ $last_seen -gt 0 ] && [ $last_seen -lt $toolate ] ; then -- 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: Kenny McCormack on 12 Jul 2010 14:45 In article <8a15fuFhq1U1(a)mid.individual.net>, Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote: .... > Avoid -a and -o; use && and ||: > >if [ $last_seen -gt 0 ] && [ $last_seen -lt $toolate ] ; then Why? (Not that I have any strong opinion on the matter, and I even agree with you, but you usually have some obscure reason for your pronouncements) -- "We should always be disposed to believe that which appears to us to be white is really black, if the hierarchy of the church so decides." - Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -
From: Chris F.A. Johnson on 12 Jul 2010 15:12 On 2010-07-12, Kenny McCormack wrote: > In article <8a15fuFhq1U1(a)mid.individual.net>, > Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote: > ... >> Avoid -a and -o; use && and ||: >> >>if [ $last_seen -gt 0 ] && [ $last_seen -lt $toolate ] ; then > > Why? > > (Not that I have any strong opinion on the matter, and I even agree with > you, but you usually have some obscure reason for your pronouncements) I can't cite chapter and verse OTTOMH, but I recall seeing an Open Group recommendation about not using -a and -o. -- 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)
|
Next
|
Last
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? |