IRIX - ksh use of set -x

IRIX - ksh use of set -x

am 03.11.2007 21:05:45 von John Horne

Hello,

I am trying to resolve a problem in a script which is being used by an
IRIX 6.5 user. I gather that by default the IRIX root account uses tcsh,
but the script starts with '#! /bin/sh', and 'sh' is the Korn shell.

The problem is that the script uses 'set -x' for tracing at one point.
This works fine in the main script, but it seems that the tracing does
not carry through to functions coded in the script. Simple example:

today_is() {
date
return
}

set -x
echo Starting...
today_is
echo ending.

The 'set -x' will cause the 'echo' statements and the 'today_is' function
name to be echoed, but the 'date' command in the function is not. I don't
want to have to use 'set -x' in every function because the script is
large and has many defined functions.

This use of 'set -x' works fine under Linux, Solaris (using ksh), AIX,
and *BSD. IRIX is the only O/S that has caused a problem.

Anyone, know how I can get IRIX to use tracing within functions without
having to 'set -x' in each of them?



Thanks,

John.

Re: IRIX - ksh use of set -x

am 04.11.2007 10:23:41 von Stephane CHAZELAS

2007-11-03, 20:05(+00), John Horne:
[...]
> I am trying to resolve a problem in a script which is being used by an
> IRIX 6.5 user. I gather that by default the IRIX root account uses tcsh,
> but the script starts with '#! /bin/sh', and 'sh' is the Korn shell.
>
> The problem is that the script uses 'set -x' for tracing at one point.
> This works fine in the main script, but it seems that the tracing does
> not carry through to functions coded in the script. Simple example:
>
> today_is() {
> date
> return
> }
>
> set -x
> echo Starting...
> today_is
> echo ending.
>
> The 'set -x' will cause the 'echo' statements and the 'today_is' function
> name to be echoed, but the 'date' command in the function is not. I don't
> want to have to use 'set -x' in every function because the script is
> large and has many defined functions.
>
> This use of 'set -x' works fine under Linux, Solaris (using ksh), AIX,
> and *BSD. IRIX is the only O/S that has caused a problem.
>
> Anyone, know how I can get IRIX to use tracing within functions without
> having to 'set -x' in each of them?
[...]

Yes, that's a known annoying /feature/ of ksh88.

You can add a:

eval "typeset -ft $(typeset +f)"

after your function declarations.


--
Stéphane

Re: IRIX - ksh use of set -x

am 04.11.2007 14:46:57 von Sven Mascheck

John Horne wrote:

> 'set -x' works fine under Linux, Solaris (using ksh), [...]

Solaris: have you confused the ksh with the Bourne shell?

Re: IRIX - ksh use of set -x

am 04.11.2007 20:42:41 von John Horne

On Sun, 04 Nov 2007 14:46:57 +0100, Sven Mascheck wrote:

> John Horne wrote:
>
>> 'set -x' works fine under Linux, Solaris (using ksh), [...]
>
> Solaris: have you confused the ksh with the Bourne shell?
>
No, the original script detects it's not running ksh and so execs to it.
By the time the 'set -x' is reached, ksh is the interpreter being used.

However, re-testing this does indeed show that the use of 'set -x' alone
does not work under Solaris 10 ksh.


John.

Re: IRIX - ksh use of set -x

am 04.11.2007 20:46:47 von John Horne

On Sun, 04 Nov 2007 09:23:41 +0000, Stephane CHAZELAS wrote:

> 2007-11-03, 20:05(+00), John Horne:
> [...]

>>
>> Anyone, know how I can get IRIX to use tracing within functions without
>> having to 'set -x' in each of them?
> [...]
>
> Yes, that's a known annoying /feature/ of ksh88.
>
> You can add a:
>
> eval "typeset -ft $(typeset +f)"
>
> after your function declarations.
>
Many thanks for this, and it seems to work fine except for one point. The
'typeset +f' returns multiple function names one-per-line, causing the
'typeset -ft' not to work correctly. I resolved this simply by using an
'echo' to cause the newlines to become spaces. It then all works fine,
and tracing occurs in the functions.

Tested on Solaris 10, I'll get back to the IRIX user to see what happens.


Many thanks,

John.

Re: IRIX - ksh use of set -x

am 04.11.2007 20:51:14 von Stephane CHAZELAS

2007-11-04, 19:46(+00), John Horne:
> On Sun, 04 Nov 2007 09:23:41 +0000, Stephane CHAZELAS wrote:
>
>> 2007-11-03, 20:05(+00), John Horne:
>> [...]
>
>>>
>>> Anyone, know how I can get IRIX to use tracing within functions without
>>> having to 'set -x' in each of them?
>> [...]
>>
>> Yes, that's a known annoying /feature/ of ksh88.
>>
>> You can add a:
>>
>> eval "typeset -ft $(typeset +f)"
>>
>> after your function declarations.
>>
> Many thanks for this, and it seems to work fine except for one point. The
> 'typeset +f' returns multiple function names one-per-line, causing the
> 'typeset -ft' not to work correctly. I resolved this simply by using an
> 'echo' to cause the newlines to become spaces. It then all works fine,
> and tracing occurs in the functions.
>
> Tested on Solaris 10, I'll get back to the IRIX user to see what happens.
[...]

Oh yes sorry,

typeset -ft $(typeset +f)

will do then as long as you don't modify $IFS.

Or

eval "typeset -ft $(typeset +f | paste -s -)"

--
Stéphane