sh script help with numeric values

markham breitbach markham at ssimicro.com
Wed Feb 3 05:11:27 UTC 2016


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 at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe at freebsd.org"



More information about the freebsd-questions mailing list