OpenSolaris

Printable Version Enter a New Search
Bug ID 4201349
Synopsis *ksh* typeset width specifier & right justify & trailing space corrupts string
State 10-Fix Delivered (Fix available in build)
Category:Subcategory shell:korn
Keywords -R | justify | ksh | typeset
Responsible Engineer Ajay Singh
Reported Against 2.6 , solaris_2.6
Duplicate Of
Introduced In
Commit to Fix s81_03
Fixed In s81_03
Release Fixed solaris_9(s81_03)
Related Bugs 1256158 , 4208891 , 6437624 , 4113420
Submit Date 7-January-1999
Last Update Date 7-January-1999
Description
The ksh builtin "typeset" for setting attributes on shell variables can be
used to right justify a string with a given field width.

From Solaris 2.6 onwards this is broken.

Simple example:

  2.6$ typeset -R2 x
  2.6$ x="A "  <- 1 space
  2.6$ echo "*$x*"
  * A*

  (Everything fine so far, ie remove trailing white space to right justify
   then truncate to the rightmost 2 characters)

  2.6$ x="A  " <- 2 spaces
  2.6$ echo "*$x*"
  *   *

Evidently broken.  Not only has the "A" vanished, but the string is 3
characters wide!

Solaris 2.5.1 is fine:

  2.5.1$ typeset -R2 x
  2.5.1$ x="A  "
  2.5.1$ echo "*$x*"
  * A*

The same problem happens with -Z -- right justify, but pad with "0" if
the first non-blank is a digit:

  2.6$ x="8 "
  2.6$ echo "*$x*"
  "08"
  2.6$ x="8  "
  2.6$ echo "*$x*"
  *   *
Work Around
Use 2.5.1 ksh, or CDE's dtksh (/usr/dt/bin/dtksh).

The last point however carries with it the disclaimer that ksh is based
upon ksh88f, whereas dtksh is ksh93.  See:

  Bug Id: 4113420
  Synopsis: *ksh* request for ksh93 integration

There's various differences between these implementations, one obvious
difference, cited in:

  Bug# 1256158, 
  Synopsis: *ksh* $0 inside a function is alway 'ksh'

ie, the value of $0 is different in dtksh inside a function (function name),
whereas it is the argv[0] for ksh.

Simply switching to dtksh may have unexpected side effects because of
these differences.
Comments
N/A