From: Lao Ming on
I have a line of bash code that fails sometimes and there's nothing I
can do about it except possibly do something on failure. The line of
code, not being very straight forward, would probably be a distraction
so I'll simplify it:

( program -a -b ) > /dev/null

Should I enclose the entire line in another set of parens like this or
is there a better way to do it?

(( program -a -b ) > /dev/null ) || error=true
if [ ! $error ]
then
... normal processing
else
... alternate processing
fi


Thanks.

Lao-Ming
From: Ben Finney on
Lao Ming <laomingliu(a)gmail.com> writes:

> I have a line of bash code that fails sometimes and there's nothing I
> can do about it except possibly do something on failure. The line of
> code, not being very straight forward, would probably be a distraction
> so I'll simplify it:
>
> ( program -a -b ) > /dev/null

Having simplified it, it's impossible to tell whether there was anything
wrong with the original.

Can you, instead, craft a minimal example that anyone here can run to
see the same behaviour you're seeing?

--
\ “It is far better to grasp the universe as it really is than to |
`\ persist in delusion, however satisfying and reassuring.” —Carl |
_o__) Sagan |
Ben Finney
From: Seebs on
On 2010-01-20, Lao Ming <laomingliu(a)gmail.com> wrote:
> I have a line of bash code that fails sometimes and there's nothing I
> can do about it except possibly do something on failure.

Okay. So what?

I mean, "false" fails sometimes -- in fact, modulos bugs, it fails all
the time.

So what? Check $? to find out whether it succeeded or failed.

Or do you mean that you have a line of code which somehow causes the
script containing it to abort? If you do, either you're using "set -e"
inappropriately, or you have found a shell bug.

-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: Bill Marcum on
On 2010-01-20, Lao Ming <laomingliu(a)gmail.com> wrote:
> I have a line of bash code that fails sometimes and there's nothing I
> can do about it except possibly do something on failure. The line of
> code, not being very straight forward, would probably be a distraction
> so I'll simplify it:
>
> ( program -a -b ) > /dev/null
>
> Should I enclose the entire line in another set of parens like this or
> is there a better way to do it?
>
> (( program -a -b ) > /dev/null ) || error=true
> if [ ! $error ]
> then
> ... normal processing
> else
> ... alternate processing
> fi
>
>
> Thanks.
>
> Lao-Ming

if program -a -b >/dev/null

From: Lao Ming on
On Jan 19, 7:39 pm, Lao Ming <laoming...(a)gmail.com> wrote:
> I have a line of bash code that fails sometimes and there's nothing I
> can do about it except possibly do something on failure.  The line of
> code, not being very straight forward, would probably be a distraction
> so I'll simplify it:
>
>  ( program -a -b  )  > /dev/null
>
> Should I enclose the entire line in another set of parens like this or
> is there a better way to do it?
>
>  (( program -a -b  )  > /dev/null ) || error=true
> if [ ! $error ]
> then
>     ... normal processing
> else
>     ... alternate processing
> fi
>
> Thanks.
>
> Lao-Ming

Thanks for all the replies. I'll have to investigate this further
before replying to anything specifically because I just ran the
software from the shell (rather than my script) and the output file
does get created when used with one of the problem URLs -- it works
fine in my shell script with 90-98 percent of the URLs. It's weird
but when I grep for the program invocation (of the downloaded
software) in the log file from the last successful run, I can't seem
to locate it but I am getting results so I know it has to be
executing. Strange. The reason I have to test for failure is that I
can't predict what URL will be a problem and I can't continue
processing of a file that is either incompletely written or does not
exist at all. Hmmm. Can a file that is incompletely written be
tested?