[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: for loop in makefile
From: |
Wayne Throop |
Subject: |
Re: for loop in makefile |
Date: |
Wed, 10 Jul 2002 23:20:13 GMT |
: address@hidden (Ed Wong)
: I need to have a simple loop in makefile to unzip and rename all the
: nc*.gz files in current directory. The following is how I do it in
: shell script and I need to put it in makefile. Anyone know how to do
: it? Thanks in advance.
:
: for file in `ls nc*.gz`
: do
: base=`echo $file | awk -F. '{ print $1 }'`
: $unzip $file
: mv -f $base $base.txt
: done
:
: ewong
One straightforward way is
$(foreach f,$(basename $(wildcard nc*.gz)),gunzip $f.gz; mv -f $f $f.txt;)
but that may cause problems if there are enough files to overflow
the maximum shell argument list size... mildly unlikely, but possible.
So you could also do
for file in `ls nc*.gz`;\
do\
base=`echo $$file | awk -F. '{ print $$1 }'`;\
gunzip $$file;\
mv -f $$base $$base.txt;\
done
though it's considerably less efficient.
Slightly more efficient might be
for file in nc*.gz;\
do\
base=`basename $$file .gz`;\
gunzip $$file;\
mv -f $$base $$base.txt;\
done
( I'm assuming that "gunzip" was meant instead of "$unzip"...
if not, make the necessary substitutions. )
Did your copy of GNU make not come with the documentation of
the builtin functions such as foreach, or the documentation of
the quoting rules for shell characters?
Wayne Throop address@hidden http://sheol.org/throopw