Re: Newbie Variable Question



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.
.



Relevant Pages

  • problem with readline
    ... I have a script that queries a database, grabs a bunch of email addresses from ... push @email_list, $address; ...
    (perl.beginners)
  • Re: random problem with 8.3 from yesterday
    ... # This script format a thumb drive connected to USB as da0. ... printf "You have to run this script as 'root' to succeed.\n" ... The whole point of labeling the file system is ...
    (freebsd-stable)
  • Re: configure an awk program from file?
    ... Strip the script down to make it clearer: ... printf "\tAufwendungen:\n" ... You can re-write that with condition-action syntax as: ... You can force the "else" implementation with condition-action syntax by using a "next": ...
    (comp.lang.awk)
  • random problem with 8.3 from yesterday
    ... # This script format a thumb drive connected to USB as da0. ... printf "You have to run this script as 'root' to succeed.\n" ... When I then try to mount the device on /dev/da0a it does not work always. ...
    (freebsd-stable)
  • Re: HELP! Scripting newbie question.
    ... printf "File: $file\n" ... There is nothing in your script to do the expand of the $1. ... insert a test by doing an echo $list or echo $1 in your srcipt to ...
    (comp.unix.solaris)