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.