[ale] Scripting question

Michael Hirsch mdhirsch at gmail.com
Thu Apr 21 21:52:52 EDT 2005


On 4/21/05, Joe Steele <joe at madewell.com> wrote:
> #!/bin/bash
> srcdir="xxx"
> dstdir="yyy"
> cd "$srcdir"
> cnt=10000
> #This next line may need refining, depending on what's in "xxx"
> #and the order you want to processs the files in:
> for i in *; do
>    rpt=0
>    while [ $rpt -lt 4 ]; do
>       cp "$i" "$dstdir/aea.${cnt#1}.ppm"
>       rpt=$[ $rpt + 1 ]
>       cnt=$[ $cnt + 1 ]
>    done
> done

Wow.  that's quite clever.  I never knew you could use the # as an
operator like that.  Very nice.

Slightly less clever would be to use the printf command.  Use you code
above, but set cnt=0 initially.  Then, instead of $cnt#1" you can use
`printf "%04d" $cnt`  (note the use of backticks).

Michael



More information about the Ale mailing list