If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Preceeding zero's

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-26-04, 14:54
Bob4480 Bob4480 is offline
Registered User
 
Join Date: Feb 2004
Location: Los Angeles, CA
Posts: 28
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.
Reply With Quote
  #2 (permalink)  
Old 02-26-04, 15:33
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
With Korn Shell use 'typeset -Z'
Quote:
/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.
Reply With Quote
  #3 (permalink)  
Old 02-26-04, 15:56
Bob4480 Bob4480 is offline
Registered User
 
Join Date: Feb 2004
Location: Los Angeles, CA
Posts: 28
Quote:
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On