Date: Sun, 22 Dec 2002 21:50:29 -0500 From: Mike Jeays <mj001@rogers.com> To: Kurt Bigler <kkb@breathhost.net> Cc: BSD Freak <bsd-freak@mbox.com.au>, FreeBSD Questions <freebsd-questions@FreeBSD.ORG> Subject: Re: Padding expr output Message-ID: <3E0679F5.7020508@rogers.com> References: <BA2B968D.57E9%kkb@breathhost.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Kurt Bigler wrote: >on 12/22/02 3:57 PM, BSD Freak <bsd-freak@mbox.com.au> wrote: > > > >>Hi all, >> >>I am usiung expr in a shell script and need to pad it's output to >>always be 3 characters. An example will explain thing better: >> >>% expr 007 + 1 >>Output is 8 >> >>I need the output to be 008 >> >> >>I checked the expr man page, but nothing there solves my problem. >>Anyone out there got one? >> >> > >Don't use expr to do the formatting. > >Use some sprintf-like capability in some scripting language that supports >full functionality from the command-line. I think both awk and perl have >that capability in some form. (Maybe someone else can be more specific.) > > > Kurt Bigler > > > > >>Thanks in advance.... >> >> > > >To Unsubscribe: send mail to majordomo@FreeBSD.org >with "unsubscribe freebsd-questions" in the body of the message > > > In bash: i=8 while [ ${#i} -lt "3" ] do i="0"${i} done echo $i To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3E0679F5.7020508>