[vox-tech] Bash scripting newbie - need syntax help

Foo Lim vox-tech@lists.lugod.org
Wed, 28 Apr 2004 00:11:21 -0700 (PDT)


On Tue, 27 Apr 2004, Larry Ozeran wrote:

> Hi all -
> 
> [...]
>
> [root@localhost mailman]# rm -f error.*
> bash: /bin/rm: Argument list too long
>
> [...]
> 
> The idea is that if it can't erase all files "error.1*" because there are too many, it calls itself again and tries "error.1.1*", and so forth.
> 
> [...]
>
> I read through the bash man page 3 times, but couldn't get enough out of
> it to understand the error message: unexpected Do on line 4. The man
> page said the syntax of the for loop was "for ((exp; exp; exp)); do exp;
> done", which is what I thought I had.

Hi Larry,

Try using xargs like this:

find . -name "error*" | xargs rm

You can also try doing it through the find command like this:

find . -name "error*" -exec rm \{} \;

Finally, if you still want to get your for loop to work, you should write 
your for loop like this:

for (( i=1; i<5; i++ )); do
  echo $i  # sub your own command here
done

Notice there are no dollar signs in the assignment, the comparison, nor 
the increment.

HTH,
Foo