Prev: Question regarding libgtk2.0-dev on Linux
Next: controlling fanspeed - gnome lenny - acer laptop
From: Mart Frauenlob on 28 Jul 2010 11:30 On 28.07.2010 14:42, Jochen Schulz wrote: > Martin McCormick: >> >> ls *.[Zz][Ii][Pp] > > Note that 'ls' doesn't see this pattern at all. The pattern is expanded > by the shell to all existing files matching the pattern. This list of > files is then passed to ls. Using 'echo' would yield (almost) the same > result in this case. > >> for MAGFILE in `ls *.[Zz][Ii][Pp] $MAGDIR/`; do >> #lots of other stuff >> done > > I think you meant to write > > for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]` > > instead. [...] > Another hint: you don't need 'ls' for your case at all. 'ls' without any > parameter just prints out the names of the files that have been passed > to it by the shell. You can get away without the command substitution: > > for MAGFILE in $MAGDIR/*.[Zz][Ii][Pp] > # � > done It's actually the prefered way (quoting "$MAGDIR" would also be encouraged). Otherwise word splitting occurs on the list (files and directories with spaces in their names will fail). set +f is also required, which is the default, but sometimes turned off in non-interactive shells. Best regards Mart -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/4C504AF3.1070807(a)chello.at
From: Paul E Condon on 28 Jul 2010 13:30 On 20100728_082732, Martin McCormick wrote: > Cesar Garcia writes: > > Perhaps, try with this: > > > > for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]`; do It probably doesn't really matter in practice, but this will pick up also files that match $MAGDIR/*.zIp , etc. (mixed case) To avoid getting these, try for MAGFILE in `ls $MAGDIR/*.ZIP $MAGDIR/*.zip`; do I haven't tested this, but I'm pretty sure it will work. I prefer this in a script because I find it much faster to aprehend what is intended when reading old code. > > That worked. Thank you. > > As soon as I saw the example, I realized that in the > script, there was no way for it to know where these files were > that I was looking for. Also my thanks to the others who replied > with equally useful information. > > Martin > > > -- > To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org > with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org > Archive: http://lists.debian.org/201007281327.o6SDRWLZ070271(a)dc.cis.okstate.edu > -- Paul E Condon pecondon(a)mesanetworks.net -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/20100728172925.GB3449(a)big.lan.gnu
From: Clive Standbridge on 28 Jul 2010 13:40 > for MAGFILE in `ls *.[Zz][Ii][Pp] $MAGDIR/`; do > #lots of other stuff > done As others noted, the ls command is superfluous and possibly harmful here. One more thing you can do is case-insensitive pathname expansion: shopt -s nocaseglob for MAGFILE in $MAGDIR/*.zip do #lots of other stuff done That will work with bash (begin your script with #!/bin/bash) but not with dash as far as I know. > If I leave out the attempted regular expression of > *.[Zz][Ii][Pp], the loop works but then any other non-zip or > non-ZIP files get processed. Note that that is not a regular expression, it's a shell pattern or glob pattern. They are different, and used in different contexts. Both are immensely useful. Cheers, -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/20100728172239.GA20159(a)rimmer.esmertec.com
From: Christian Jaeger on 28 Jul 2010 14:20 > for MAGFILE in $MAGDIR/*.zip Don't forget the double quotes around variable references. It's better to always do that by default than to fix it afterwards (either because you feed it paths with whitespace in them yourself at some point or because someone else is trying to close the safety holes after you publish such a script). for MAGFILE in "$MAGDIR"/*.zip -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/AANLkTin_hPc13Qs6QjjgNyuLPw6=nThqm6oXH8iFL-8F(a)mail.gmail.com
From: Karl Vogel on 28 Jul 2010 14:40 >> On 28.07.2010 14:42, Jochen Schulz wrote: J> I think you meant to write J> for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]` J> Another hint: you don't need 'ls' for your case at all. I'd recommend keeping the "ls". Try your script when MAGDIR doesn't have any zipfiles, and MAGFILE will hold the expanded value of $MAGDIR with the string "*.[Zz][Ii][Pp]" appended. Bash, sh, and ksh all do that for some dopey reason, which is why I would do for file in $(ls $MAGDIR/*.[Zz][Ii][Pp] 2> /dev/null); do ... if there's any chance that you won't find any files. -- Karl Vogel I don't speak for the USAF or my company Love and respect for the great American experiment in free government does not appear out of thin air. --Larry P. Arnn -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/20100728180522.353A1BED9(a)kev.msw.wpafb.af.mil
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Question regarding libgtk2.0-dev on Linux Next: controlling fanspeed - gnome lenny - acer laptop |