From owner-freebsd-questions@freebsd.org Wed Feb 3 05:11:26 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EBBEAA99E55 for ; Wed, 3 Feb 2016 05:11:26 +0000 (UTC) (envelope-from markham@ssimicro.com) Received: from mail.ssimicro.com (mail.ssimicro.com [64.247.129.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.ssimicro.com", Issuer "RapidSSL SHA256 CA - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id ACAECD8F for ; Wed, 3 Feb 2016 05:11:26 +0000 (UTC) (envelope-from markham@ssimicro.com) Received: from Markhams-MacBook-Pro.local (64-247-134-200.ssimicro.com [64.247.134.200]) (authenticated bits=0) by mail.ssimicro.com (8.14.7/8.14.7) with ESMTP id u1357r0Y020841 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Tue, 2 Feb 2016 22:07:54 -0700 (MST) Subject: Re: sh script help with numeric values To: Ernie Luzar , Freebsd Questions References: <56B1765D.2060800@gmail.com> From: markham breitbach Message-ID: <56B18BF4.6030002@ssimicro.com> Date: Tue, 2 Feb 2016 22:11:16 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56B1765D.2060800@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2016 05:11:27 -0000 I've always liked jot for this sort of thing: dirname="dir" start=0 count=5 for i in `jot -w%03d $count $start`; do echo $dirname-$i done -Markham On 2016-02-02 8:39 PM, Ernie Luzar wrote: > Hello list > > I am having trouble getting leading zeros to show up. > The following is an example of what i mean. > > dirname="dir" > dup_count=000 > dup_times=5 > > while [ "${dup_count}" -ne "${dup_times}" ]; do > dup_count=$(( $dup_count + 001 )) > dname="${dirname}-${dup_count}" > echo "${dname}" > done > > Outputs this > dir-1 > dir-2 > dir-3 > dir-4 > dir-5 > > What I really want to see is this > dir-001 > dir-002 > dir-003 > dir-004 > dir-005 > dir-013 > dir-111 > ect > > How do I get the leading zeros to show? > > Thanks for your help > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org"