Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Location
    Los Angeles, CA
    Posts
    28

    Unanswered: Preceeding zero's

    Is there a way to force preceeding zero's into the echo statement for integers? See example:

    $ MYVAR=0001
    $ echo $MYVAR
    0001
    $ ((MYVAR=MYVAR+1))
    $ echo $MYVAR
    2

    I know I could do his with a shell by comparing the length of the variable and adding zero's, but thought there was an option that could be set to do this automatically.

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    With Korn Shell use 'typeset -Z'
    /home/jp> typeset -i -Z5 my_integer
    /home/jp> my_integer=321
    /home/jp> echo $my_integer
    00321
    /home/jp>
    Seems that there is no equivalent with bash.
    Jean-Pierre.

  3. #3
    Join Date
    Feb 2004
    Location
    Los Angeles, CA
    Posts
    28
    Originally posted by aigles
    With Korn Shell use 'typeset -Z'


    Seems that there is no equivalent with bash.
    Thanks ! I am using Korn, and it works great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •