bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File name/Line numbers with tracing output.


From: Dennis Williamson
Subject: Re: File name/Line numbers with tracing output.
Date: Tue, 24 Aug 2010 12:50:24 -0500

On Tue, Aug 24, 2010 at 2:44 AM, Joachim Schmitz
<address@hidden> wrote:
> Edward Peschko wrote:
>>
>> All,
>>
>> I've been working lately at upgrading my debugging tools and
>> procedures, and have come to looking how I can improve debugging
>> bash.
>> I know about bash -x , but its terribly annoying because, even though
>> it shows the evaluated text, there is no explicit way to tie that
>> output back to the script that ran it. For example, with a script
>> like:
>> echo $x
>>
>> Where x = 1, when you run bash -x , you will see:
>>
>> + echo 1
>>
>> With no obvious way to tie this back to the place in the script that
>> ran bash.
>>
>> What I was wondering is if there was a way to make this explicit, ie:
>> bash -X (or somesuch) which would output something like:
>> ltmain.sh:110 + echo 1
>>
>> Where ltmain.sh is the name of the script, and line 110 is the line #
>> of the associated program.
>> So - does something like this exist, and if not, would it be easy to
>> add?
>> Thanks,
>
>
> Have a look at PS4.
> Defeult is "+ ", but you could set it to e.g.
> PS4='$0:${LINENO} + '
>
>
>
> Bye, Jojo
>
>

In addition to setting PS4, you can use -v along with -x to output the
script's lines without expansions.

#!/bin/bash -vx
x=42
echo $x

Output (with a default PS4):

#!/bin/bash -xv
x=42
+ x=42
echo $x
+ echo 42
42

Other variables worth considering for inclusion in PS4 include:

$?
$_
address@hidden
$FUNCNAME (or address@hidden )
etc.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]