adjusting string var to fixed length (in ksh)

Mark Lanzo lanzo at wgate.UUCP
Thu Jun 13 06:54:21 AEST 1991


"Mark" == Mark Lanzo <lanzo at atesysv.UUCP>    [that's me]
"Dan"  == Dan_Jacobson at ihlpz.ATT.COM 

>From prior posts:
    Mark> If you are using "ksh" [...]
    
    Mark> 	myname=Mark
    Mark> 	typeset -L10 myname
    
Dan>    In my prompt I wanted to put $? (last command exit status) in a fixed
Dan>    width... (PS1='$? '...) but I can't typeset -L3 ? or \?...

Hmm.  As far as I know, you're out of luck with this.
You're right, "typeset" doesn't work on special parameters like "$?"; 
it just complains that "?" isn't a valid identifier.

Even if "typeset" _did_ work on $?, I think you'd still be out of luck.
Ksh evaluates PS1 and performs *parameter substitution* on the string,
but it does not perform *command substitution* on it.  (Drats!)

In other words, you can't use the `command` or $(command) forms within
PS1 in any meaningful fashion.

For example, to display the current directory in the prompt:
      PS1='$PWD> '        # Works
      PS1='`pwd`> '       # Does not work
      PS1='$(pwd)> '      # Does not work

I even tried screwier things, to see if any sort of recursive evaluation
mechanisms could be faked out, such as

      PS1='${?:+`pwd`}'

... to no avail.


If anyone else has a solution, I'd like to hear about it ...
                    -- Mark --



More information about the Comp.unix.shell mailing list