ksh command substitution and typeset

ksh command substitution and typeset

am 04.10.2007 15:03:30 von Bernd Eggink

Can anybody explain the behaviour of this function?

function f
{
typeset p=f t

ksh --version
set -x
typeset +f $p
t=$(typeset +f $p)
print "$t"
}

Calling f (on Linux) produces this output:

version sh (AT&T Research) 1993-12-28 s+
+ typeset +f f
f #line 1 /local/bernd/tst/k
+ typeset +f f
+ t=''
+ print ''

Why does the assignment t=$(typeset +f $p) give an empty result, while
t=$(typeset +f f) works as expected?

If "typeset +f" is replaced by "print", there is no such discrepancy.
Looks like a bug to me, but I may be missing something.

Regards,
Bernd

--
Bernd Eggink
monoped@sudrala.de
http://sudrala.de

Re: ksh command substitution and typeset

am 04.10.2007 17:49:56 von Icarus Sparry

On Thu, 04 Oct 2007 15:03:30 +0200, Bernd Eggink wrote:

> Can anybody explain the behaviour of this function?
>
> function f
> {
> typeset p=f t
>
> ksh --version
> set -x
> typeset +f $p
> t=$(typeset +f $p)
> print "$t"
> }
>
> Calling f (on Linux) produces this output:
>
> version sh (AT&T Research) 1993-12-28 s+
> + typeset +f f
> f #line 1 /local/bernd/tst/k
> + typeset +f f
> + t=''
> + print ''
>
> Why does the assignment t=$(typeset +f $p) give an empty result, while
> t=$(typeset +f f) works as expected?
>
> If "typeset +f" is replaced by "print", there is no such discrepancy.
> Looks like a bug to me, but I may be missing something.
>
> Regards,
> Bernd

If you run
typeset --man
you will see

typeset is built-in to the shell as a declaration command so that
field splitting and pathname expansion are not performed on the
arguments. Tilde expansion occurs on value.

I agree it does not mention if parameter expansion does or doesn't take
place. I suggest you email the ast-users list to point out that either
the manual page needs to be improved, or the code changed.

https://mailman.research.att.com/mailman/listinfo/ast-users/

Re: ksh command substitution and typeset

am 04.10.2007 19:40:41 von Bernd Eggink

Icarus Sparry schrieb:
> On Thu, 04 Oct 2007 15:03:30 +0200, Bernd Eggink wrote:
>
>> Can anybody explain the behaviour of this function?
>>
>> function f
>> {
>> typeset p=f t
>>
>> ksh --version
>> set -x
>> typeset +f $p
>> t=$(typeset +f $p)
>> print "$t"
>> }
>>
>> Calling f (on Linux) produces this output:
>>
>> version sh (AT&T Research) 1993-12-28 s+
>> + typeset +f f
>> f #line 1 /local/bernd/tst/k
>> + typeset +f f
>> + t=''
>> + print ''
>>
>> Why does the assignment t=$(typeset +f $p) give an empty result, while
>> t=$(typeset +f f) works as expected?
>>
>> If "typeset +f" is replaced by "print", there is no such discrepancy.
>> Looks like a bug to me, but I may be missing something.
>>
>> Regards,
>> Bernd
>
> If you run
> typeset --man
> you will see
>
> typeset is built-in to the shell as a declaration command so that
> field splitting and pathname expansion are not performed on the
> arguments. Tilde expansion occurs on value.
>
> I agree it does not mention if parameter expansion does or doesn't take
> place. I suggest you email the ast-users list to point out that either
> the manual page needs to be improved, or the code changed.
>
> https://mailman.research.att.com/mailman/listinfo/ast-users/

I'll do that. Actually the behaviour is not even consistent, as
t=$(typeset +f $1) _works_.

Bernd

--
Bernd Eggink
monoped@sudrala.de
http://sudrala.de