Re: Newbie Variable Question
- From: Ed Morton <morton@xxxxxxxxxxxxxx>
- Date: Wed, 09 Aug 2006 21:51:41 -0500
dawaves wrote:
hello,
I have a Variable that is a single numeric value, let's say it's "1" or
"8". Is there a way to make that Variable into "01" or "08".
Basically its a variable that gets the current day. So in my script, I
calculate the current day and populate that variable.
But later on in the script, I need that value to be 2 digits, not 1
digit. So if today is August 9th, the variable will be "9", but I need
"09".
Any suggestions?
Thanks!
Are you sure that needs to be one digiti initially? You might be better off just using the 2-digit format everywhere. Anyway, to your question:
If your shell supports printf:
$ printf "%02d\n" 1
01
$ printf "%02d\n" 10
10
$ printf "%02d\n" 100
100
Regards,
Ed.
.
- Follow-Ups:
- Re: Newbie Variable Question
- From: Chris F.A. Johnson
- Re: Newbie Variable Question
- References:
- Newbie Variable Question
- From: dawaves
- Newbie Variable Question
- Prev by Date: Re: prob relating sed
- Next by Date: Re: Progress indicator/Slide to show script in progress
- Previous by thread: Re: Newbie Variable Question
- Next by thread: Re: Newbie Variable Question
- Index(es):
Relevant Pages
|