adjusting string var to fixed length (in ksh)

Stephen Vinoski vinoski at apollo.hp.com
Fri Jun 14 01:11:12 AEST 1991


In article <193 at atesysv.UUCP> lanzo at atesysv.UUCP (Mark Lanzo) writes:
>"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.

If your ksh is newer than the 06/86 version, how about this:

  typeset -L3 st=0
  trap 'st=$?' DEBUG
  PS1='$st '


-steve

| Steve Vinoski  (508)256-0176 x5904       | Internet: vinoski at apollo.hp.com  |
| HP Apollo Division, Chelmsford, MA 01824 | UUCP: ...!apollo!vinoski         |



More information about the Comp.unix.shell mailing list