From: Wayne on
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
From: Thomas 'PointedEars' Lahn on
Chris F.A. Johnson wrote:

> 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.

See the Single UNIX® Specification, Version 3 (SUSv3) at
<http://www.opengroup.org/onlinepubs/000095399/utilities/test.html>, under
"Application Usage". Note, however, that this non-normative recommendation
refers to user-supplied input. So ISTM that in all other cases the options
should be preferred as they do not require another invocation of test(1).

On a side node, I have newly discovered link to a Firefox Search Plugin
there; it leads to
<http://mycroft.mozdev.org/download.html?name=unix.org&submitform=Search>
which works quite well in Iceweasel 3.6.3.

--
PointedEars
From: Sven Mascheck on
Chris F.A. Johnson wrote:
> On 2010-07-12, Kenny McCormack wrote:
>> Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
>> ...
>>> Avoid -a and -o; use && and || [...]
>>>
>> Why?
>>
> I can't cite chapter and verse OTTOMH, but I recall seeing an Open
> Group recommendation about not using -a and -o.

In the posix description of the "test" command these features are
marked as "obsolescent". Strictly conforming applications shall not
use them, and they might be removed in a future version of posix.
The informative section "application usage" explains that some
expressions are ambiguous depending on the specific expressions
being used.


A drastic example,
especially if the input is not well known:

test -n "$a" -a -n "$b" || echo at-least-one-is-empty

with
a==; b=x

This wrongly echoes or even yields a syntax error in current
bash, ksh93 and dash, and also in ksh88 and most bourne shells.


BTW, noteworthy differences are:
- && and || have equal precedence (order matters)
- most shells always evaluate both sides of -a or -o,
even if they could stop after the left expression.

--
http://www.in-ulm.de/~mascheck/various/test/
From: Kenny McCormack on
In article <i1g0mbUf5mL1(a)news.in-ulm.de>,
Sven Mascheck <mascheck(a)email.invalid> wrote:
>Chris F.A. Johnson wrote:
>> On 2010-07-12, Kenny McCormack wrote:
>>> Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
>>> ...
>>>> Avoid -a and -o; use && and || [...]
>>>>
>>> Why?
>>>
>> I can't cite chapter and verse OTTOMH, but I recall seeing an Open
>> Group recommendation about not using -a and -o.
>
>In the posix description of the "test" command these features are
>marked as "obsolescent". Strictly conforming applications shall not
>use them, and they might be removed in a future version of posix.
>The informative section "application usage" explains that some
>expressions are ambiguous depending on the specific expressions
>being used.
>
>
>A drastic example,
>especially if the input is not well known:
>
> test -n "$a" -a -n "$b" || echo at-least-one-is-empty
>
>with
> a==; b=x
>
>This wrongly echoes or even yields a syntax error in current
>bash, ksh93 and dash, and also in ksh88 and most bourne shells.
>
>
>BTW, noteworthy differences are:
>- && and || have equal precedence (order matters)
>- most shells always evaluate both sides of -a or -o,
> even if they could stop after the left expression.

These are convincing arguments.

I never liked -a and -o anyway.

--
"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: realto on
On Jul 12, 6:21 pm, Lew Pitcher <lpitc...(a)teksavvy.com> wrote:

[deletia]

Brampton's Lew Pitcher, who worked 25 years at the TDBank, is a
cowardly little domain thief. Watch out for him.

Check out http://lewpitcher.ca for further details.

Don't say you were not warned!