weird output with typeset -F

weird output with typeset -F

Post by b.. » Thu, 17 Feb 2005 03:56:10



Does someone know why I have the weird output in the following piece of
code?

typeset -F5 X=123.456
print $X              
5#443

Thanks,
Bernard

 
 
 

weird output with typeset -F

Post by Chris Bart » Thu, 17 Feb 2005 04:40:06



> Does someone know why I have the weird output in the following piece of
> code?

> typeset -F5 X=123.456
> print $X              
> 5#443

Which shell are you using? Under zsh 4.0.7, I get:

typeset -F5 X=123.456
print $X
123.45600

 
 
 

weird output with typeset -F

Post by b.. » Thu, 17 Feb 2005 04:59:38


I use ksh on AIX.
 
 
 

weird output with typeset -F

Post by bsh » Thu, 17 Feb 2005 06:48:23



> Does someone know why I have the weird output in the following piece
of
> code?
> typeset -F5 X=123.456
> print $X
> 5#443

I would have said that ksh on AIX is _apparently_ ksh version 1993
or newer, which is the only distribution kornshell which implements
the -F (floating point) option to the builtin command typeset;
however, the "5" parameter option is parsed in the context of the
-i option, wherein it defines the radix of the display, not the
formatted width of the display, as it should.

I presume you understand that what "5#443" is telling you is
that 443 is base 5 for 123 [base 10].

Although I cannot verify this, in my experience, AIX OS and apps
are inappropriately "munged" as IBM's source license will allow,
as well as exhibiting "hybrid" characteristics between canonical
distribution versions of apps and tools. This is certainly true
of my experiences with the AIX port of sed(1), which was working
just fine until some IBM programmer was told to remove all
identifying information in sed(1) diagnostic output!

As AIX ksh is truncating the result, it is behaving as if IBM had
added in their ksh88 the compatibility option -F as an "alias" to
option -i. The exhibited behavior is how many (but not all) ksh88
ports work: they accept floating point notation, but do implicit
integral truncation.

A BIG :( for AIX!

I would use the below as a workaround. This solution has the merit
of at least being compatible to non-broken versions of ksh93!

# AIX: use base 10 as radix (default)
# UNIX: 10 char width (default)
typeset -F10 X=123.456
print -f %5d $X

But this is not going to help you if you genuinely need to do
floating point operations in ksh93. In that case, your two alternatives
are to either use dc(1)/bc(1), or download a _real_ ksh93 port for AIX
from:

http://www.research.att.com/sw/download/

=Brian

 
 
 

weird output with typeset -F

Post by Dan Merce » Thu, 17 Feb 2005 06:53:00


: I use ksh on AIX.
:

Isn't that ksh88?  Floating point is a ksh93 feature (which should be
available,  at least as dtksh).  What is the result of

    $ print ${.sh.version}

?

Dan Mercer

 
 
 

weird output with typeset -F

Post by Fran » Thu, 17 Feb 2005 09:16:35


If you're on Aix 5 use /usr/bin/ksh93.


Quote:> Does someone know why I have the weird output in the following piece of
> code?

> typeset -F5 X=123.456
> print $X
> 5#443

> Thanks,
> Bernard

 
 
 

weird output with typeset -F

Post by Ber » Sat, 19 Feb 2005 03:32:25



> If you're on Aix 5 use /usr/bin/ksh93.



> > Does someone know why I have the weird output in the following piece of
> > code?

> > typeset -F5 X=123.456
> > print $X
> > 5#443

> > Thanks,
> > Bernard

Gentlemen,

My version of ksh is 88 and the beast where I need the floating point
is AIX 4.3.  Also, on the beast with AIX 5.2, the floating point on
ksh93 works just fine.

The option -f in the command `print -f %d5 $X` does not work.

I don't want to install ksh93 on my 4.3 box therefore I'll try to
swith to perl.

thanks to everyone,

Bernard

 
 
 

1. typeset -f gives funny output when executed from Korn shell script

I just discovered a funny behaviour of the typeset -f command when
executed in a shell script.

Assume function a is defined in your ENV file (.kshrc)

---------- begin .kshrc
function a {
        : # this is function a
---------- end .kshrc

and file foo contains the following lines

---------- begin foo
function b {
        : # this is function b

typeset -f
---------- end foo

Sourcing foo gives the following output

---------- begin output of ". foo"
function a
{
        : # this is function a
function b
{
        : # this is function b
---------- end output of ". foo"

while executing foo gives

---------- begin output of "foo"
function a
{
<command unknown>
function b
---------- end output of "foo"

and, as you might (not) expect :

---------- begin output of "ksh foo"
function a
function b
---------- end output of "ksh foo"

Is this typycal to my implementation of the Korn shell (HP 9000/400,
HP-UX 8.0) or is it a
        - ksh bug,
        - ksh undocumented feature,
        - ksh documented feature well hidden in TFM?

Marc.
--
Marc PHILIPS                    Eurocontrol - Central Flow Management Unit

Tel: +32 2 729 33 09            B-1040 BRUXELLES
Fax: +32 2 729 32 16            Belgium

2. PnP sound in the new pre 2.2 kernel

3. Weird Ping, weird FTP, weird Telnet... HELP!!!

4. isdn questions

5. Weird, weird, weird issue ....

6. Kill() changed?

7. Sar weird output question

8. Screen Capture 4 Linux?

9. Weird Bug - Output redirection causes coredump

10. Weird 'last' output?

11. ldd with weird output

12. Weird output from 'who'

13. Fwd: Re: [BUG][2.5.64bk4] Weird problem with 2 PCs - OUTPUT OF PANIC