From: boblatest on
On Jul 12, 9:24 pm, Wayne <nos...(a)all.invalid> wrote:
> On 7/12/2010 2:00 PM, Robert Latest wrote:
>
> > 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
>
> The round parenthesis need quoting:
>
>   if [ \($last_seen -gt 0\) -a \($last_seen -lt $toolate\) ] ; then
>
> --
> Wayne

Thanks! But how on God's Earth is one supposed to see that from the
manpage excerpt I quoted? I suppose it becomes clear when you read the
entire page and work out the sequence of substitution the shell makes,
but what the heck, the manpage is supposed to be a quick reference!
Sheesh.

robert
From: Janis Papanagnou on
Kenny McCormack schrieb:
> In article <tk2ug7-jtg.ln1(a)leafnode-msgid.gclare.org.uk>,
> Geoff Clare <geoff(a)clare.See-My-Signature.invalid> wrote:
> ...
>> SUSv3 was superseded by SUSv4 in 2008. Sven was referring to the
>> current standard, not the out-of-date one you were looking at.
>
> Don't confuse the pointed out with facts. They only confuse and annoy him.
>

LOL. Nice pun. :-)
From: boblatest on
On Jul 12, 8:33 pm, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote:
> 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)

Thanks, that did it. Thanks to everybody for the good replies and the
interesting discussion!

robert
From: Thomas 'PointedEars' Lahn on
boblatest wrote:

> On Jul 12, 9:24 pm, Wayne <nos...(a)all.invalid> wrote:
>> On 7/12/2010 2:00 PM, Robert Latest wrote:
>> > 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?
>>
>> The round parenthesis need quoting:
>>
>> if [ \($last_seen -gt 0\) -a \($last_seen -lt $toolate\) ] ; then
>
> Thanks! But how on God's Earth is one supposed to see that from the
> manpage excerpt I quoted?

It is not clear from which "sh" manpage you have quoted. However, to answer
your question, one would familiarize oneself with shell syntax before one
attempted to use shell utilities like `test'.

In your manpage, too, there is probably a warning just below the quoted
section that the `test' grammar is inherently ambiguous, and that, when in
doubt, the POSIX shell grammar would take precedence. The parentheses
delimit a subshell expression in sh(1), which is obviously not allowed as
positional argument to `[' (or `test'). So if they are to be interpreted by
`test' instead of `sh', they need to be escaped (but can probably be safely
omitted here instead).

BTW, your complaints are misplaced here. This is _not_ the `sh' customer
support.

--
PointedEars
From: Wayne on
On 7/14/2010 4:53 AM, boblatest wrote:
> On Jul 12, 9:24 pm, Wayne <nos...(a)all.invalid> wrote:
>> On 7/12/2010 2:00 PM, Robert Latest wrote:
>>
>>> 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
>>
>> The round parenthesis need quoting:
>>
>> if [ \($last_seen -gt 0\) -a \($last_seen -lt $toolate\) ] ; then
>>
>> --
>> Wayne
>
> Thanks! But how on God's Earth is one supposed to see that from the
> manpage excerpt I quoted? I suppose it becomes clear when you read the
> entire page and work out the sequence of substitution the shell makes,
> but what the heck, the manpage is supposed to be a quick reference!
> Sheesh.
>
> robert

Shell scripting is too complex to have every facet described on every
man page. It's elegant (in some ways), and even fun, but not simple.
You might be better served taking a course in it, or reading a good
book. To understand the more complex bits, there's always this
newgroup!

--
Wayne