From: Martin McCormick on
I could have sworn I have done this before but obviously
not because I can't get it to work no matter what I try.

I am running a shell script that is supposed to find
every .zip or .ZIP file in a directory and do an extraction of
the contents. I don't want any other files to be included in the
script as they are not zip files. What works exactly from the
command line is:

ls *.[Zz][Ii][Pp]

I get any .zip or .ZIP file that is in the directory. In the
script, there is some code as follows:

for MAGFILE in `ls *.[Zz][Ii][Pp] $MAGDIR/`; do
#lots of other stuff
done

I think I have tried about every form of escaping there
is and the error is that *.[Zz][Ii][Pp] is no such file or
directory.

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.

Many thanks for any suggestions or explanations as to
why this does not seem to work.

Martin McCormick


--
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/201007281133.o6SBX9eQ065793(a)dc.cis.okstate.edu
From: Cesar Garcia on
Perhaps, try with this:

for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]`; do





El 28/07/10 13:33, Martin McCormick escribi�:
> I could have sworn I have done this before but obviously
> not because I can't get it to work no matter what I try.
>
> I am running a shell script that is supposed to find
> every .zip or .ZIP file in a directory and do an extraction of
> the contents. I don't want any other files to be included in the
> script as they are not zip files. What works exactly from the
> command line is:
>
> ls *.[Zz][Ii][Pp]
>
> I get any .zip or .ZIP file that is in the directory. In the
> script, there is some code as follows:
>
> for MAGFILE in `ls *.[Zz][Ii][Pp] $MAGDIR/`; do
> #lots of other stuff
> done
>
> I think I have tried about every form of escaping there
> is and the error is that *.[Zz][Ii][Pp] is no such file or
> directory.
>
> 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.
>
> Many thanks for any suggestions or explanations as to
> why this does not seem to work.
>
> Martin McCormick
>
>
>


--
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/4C5019DB.6040902(a)gmail.com
From: Jordon Bedwell on
On 7/28/10 6:33 AM, Martin McCormick wrote:
> I could have sworn I have done this before but obviously
> not because I can't get it to work no matter what I try.
>
> I am running a shell script that is supposed to find
> every .zip or .ZIP file in a directory and do an extraction of
> the contents. I don't want any other files to be included in the
> script as they are not zip files. What works exactly from the
> command line is:
>
> ls *.[Zz][Ii][Pp]
>
> I get any .zip or .ZIP file that is in the directory. In the
> script, there is some code as follows:
>
> for MAGFILE in `ls *.[Zz][Ii][Pp] $MAGDIR/`; do
> #lots of other stuff
> done
>
> I think I have tried about every form of escaping there
> is and the error is that *.[Zz][Ii][Pp] is no such file or
> directory.
>
> 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.
>
> Many thanks for any suggestions or explanations as to
> why this does not seem to work.
>
> Martin McCormick
>
>

#!/bin/sh
for MAGFILE in $(ls *\.[zZ][iI][pP])
do
echo "File: $MAGFILE";
done

I would prefer to rely on $() before `` in a bash script.


--
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/4C501D35.1020907(a)envygeeks.com
From: Jochen Schulz on
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. What is happening with your version is the following:

- the shell tries to find files matching your pattern in the current
directory
- since there is no file matching your pattern, it leaves the pattern
unchanged
- $MAGDIR is expanded
- the unexpanded pattern and the content of $MAGDIR are passes to 'ls'
- 'ls' prints an error message for your pattern and lists the content of
$MAGDIR

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


J.
--
Watching television is more hip than actually speaking to anyone.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
From: Martin McCormick on
Cesar Garcia writes:
> Perhaps, try with this:
>
> for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]`; do

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