[vox-tech] Bash scripting newbie - need syntax help
Larry Ozeran
vox-tech@lists.lugod.org
Wed, 28 Apr 2004 22:33:13 -0700
Thanks for the great discussion. I really appreciate everyone's ideas.=
Unfortunately, it appears that find is using similar expansion of the *=
leading to the same error.
[root@localhost mailman]# find -iname \erro*.[1-4].[1-4] -print0 | xargs=
-r0 rm -f
bash: /usr/bin/find: Argument list too long
[root@localhost mailman]# find -iname \erro*.[1-4] -print0 | xargs -r0 rm=
-f
bash: /usr/bin/find: Argument list too long
So, it appears I will have to use recursion (though I may have=
misunderstood Bill's alternate suggestion for using xargs). Using Foo's=
corrections, I changed to the following, but have a new syntax error.
for ((i=3D1; i<5; i++)); do
echo $i $1
until rm -f $1.$i || exec bigerase $1.$i;
done
echo -n =3D
done
[root@localhost mailman]# source bigerase error
bash: bigerase: line 6: syntax error near unexpected token `done'
bash: bigerase: line 6: ` done'
I reread the man page _again_ and enclose the main parts here to ask: What=
did I misread here?
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated
according to the rules described below under ARITH=AD
METIC EVALUATION. The arithmetic expression expr2
is then evaluated repeatedly until it evaluates to
zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expres=AD
sion expr3 is evaluated. If any expression is
omitted, it behaves as if it evaluates to 1. The
return value is the exit status of the last command
in list that is executed, or false if any of the
expressions is invalid.
until list; do list; done
The while command continuously executes the do list
as long as the last command in list returns an exit
status of zero. The until command is identical to
the while command, except that the test is negated;
the do list is executed as long as the last command
in list returns a non-zero exit status. The exit
status of the while and until commands is the exit
status of the last do list command executed, or
zero if none was executed.
Do I need curly braces (or something) to notify bash there is an embedded=
control loop? It looks to me like I need both 'done' statements. I feel=
like this is a really dumb mistake, but hopefully the context of the=
problem is interesting to the group.
Thanks again,
Larry
*********** REPLY SEPARATOR ***********
On 4/28/04 at 12:11 AM Foo Lim wrote:
>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=3D1; 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
>
>_______________________________________________
>vox-tech mailing list
>vox-tech@lists.lugod.org
>http://lists.lugod.org/mailman/listinfo/vox-tech