Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Dec 2002 01:12:22 +0100
From:      Roman Neuhauser <neuhauser@bellavista.cz>
To:        BSD Freak <bsd-freak@mbox.com.au>
Cc:        FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Padding expr output
Message-ID:  <20021223001222.GA42622@freepuppy.bellavista.cz>
In-Reply-To: <108151f107bf32.107bf32108151f@mbox.com.au>
References:  <108151f107bf32.107bf32108151f@mbox.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
# bsd-freak@mbox.com.au / 2002-12-23 10:57:19 +1100:
> 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

    printf(8)

    zero-padded integer and octal, respectively:
    roman@freepuppy ~ 1029:0 > printf "%03d\n" $(expr 8 + 1)       
    009
    roman@freepuppy ~ 1030:0 > printf "%#o\n" $(expr 8 + 1)           
    011
    roman@freepuppy ~ 1031:0 >  

-- 
If you cc me or remove the list(s) completely I'll most likely ignore
your message.    see http://www.eyrie.org./~eagle/faqs/questions.html

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?20021223001222.GA42622>