From: John Kelly on

Suppose I want to bail out of a script if any command exits with a
non-zero status. AND, I want to know what line caused the problem.

set -e

will do it, but who knows what line aborted?

trap 'echo $LINENO' ERR

doesn't help either, because it reports the trap line, not what caused
the trap.



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: Eric on
On 2010-08-12, John Kelly <jak(a)isp2dial.com> wrote:
>
> Suppose I want to bail out of a script if any command exits with a
> non-zero status. AND, I want to know what line caused the problem.
>
> set -e
>
> will do it, but who knows what line aborted?
>
> trap 'echo $LINENO' ERR
>
> doesn't help either, because it reports the trap line, not what caused
> the trap.
>

No it doesn't.

trap "echo $LINENO" ERR

would do that.

Eric
From: John Kelly on
On Thu, 12 Aug 2010 21:51:03 +0100, Eric <eric(a)deptj.eu> wrote:

>On 2010-08-12, John Kelly <jak(a)isp2dial.com> wrote:
>>
>> Suppose I want to bail out of a script if any command exits with a
>> non-zero status. AND, I want to know what line caused the problem.
>>
>> set -e
>>
>> will do it, but who knows what line aborted?
>>
>> trap 'echo $LINENO' ERR
>>
>> doesn't help either, because it reports the trap line, not what caused
>> the trap.
>>
>
>No it doesn't.
>
>trap "echo $LINENO" ERR
>
>would do that.

#!/bin/sh

trap "echo trap at $LINENO" ERR

let x=0
let y=0
let z=0

# ./xs
trap at 3
trap at 3
trap at 3


Nice try but no cigar.



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: Seebs on
On 2010-08-12, John Kelly <jak(a)isp2dial.com> wrote:
> Suppose I want to bail out of a script if any command exits with a
> non-zero status. AND, I want to know what line caused the problem.

Oh, interesting. Have you considered also asking for a pony? :P

> set -e

> will do it, but who knows what line aborted?

> trap 'echo $LINENO' ERR

> doesn't help either, because it reports the trap line, not what caused
> the trap.

This surprises me, and I was about to give you the same answer you already
got, but apparently that's wrong. However...

#!/bin/sh
trap 'echo error occurred on line: $LINENO' ERR

set -e

true
false

When I run this, I get:

error occurred on line: 7

So I get the behavior we expected. Hmmmm.

-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: Seebs on
On 2010-08-12, John Kelly <jak(a)isp2dial.com> wrote:
> #!/bin/sh
>
> trap "echo trap at $LINENO" ERR
>
> let x=0
> let y=0
> let z=0
>
> # ./xs
> trap at 3
> trap at 3
> trap at 3

> Nice try but no cigar.

Uh.

Maybe you have a font problem?

You have double quotes (") there, with which you get this behavior.

I changed it to:
trap 'echo trap at $LINENO' ERR

and got:

trap at 5
trap at 6
trap at 7

Eric's suggestion (use single quotes, aka apostrophes, rather than double
quotes) appears to do exactly the right thing.

Can you tell these apart on your display?
' (single quote)
" (double quote)

-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!
 |  Next  |  Last
Pages: 1 2 3
Prev: download basics
Next: gnu-make prerequisites