l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2004 Apr 28 22:40

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Bash scripting newbie - need syntax help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



Why not just do the other way Foo suggested?:

   find -iname \erro*.[1-4].[1-4] -exec rm -f \{} \;

-Mark?


On Wed, 28 Apr 2004, Larry Ozeran wrote:

> 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=1; i<5; i++)); do
>   echo $i $1
>   until rm -f $1.$i || exec bigerase $1.$i;
>   done
>   echo -n =
> 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­
>               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­
>               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=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
> >
> >_______________________________________________
> >vox-tech mailing list
> >vox-tech@lists.lugod.org
> >http://lists.lugod.org/mailman/listinfo/vox-tech
>
>
>
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech
>
>

-- 
Mark K. Kim
AIM: markus kimius
Homepage: http://www.cbreak.org/
Xanga: http://www.xanga.com/vindaci
Friendster: http://www.friendster.com/user.jsp?id=13046
PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
PGP key available on the homepage
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.