Re: What Will This Return?
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Fri, 30 Mar 2007 07:03:48 GMT
2007-03-29, 12:05(-07), Will:
[...]
[...]NonEmptyFiles=$( find /usr/edit/*.phy -type f -size +0 )
So I can just use:?[...]
for EachFile in $NonEmptyFiles
do
TimeStamp=`date "+%Y%m%d%H%M"`
cp $EachFile $EachFile$TimeStamp.dat
done
No, with $NonEmptyFiles unquoted above, you're asking the shell
to split the content of $NonEmptyFiles on spaces and to perform
filename generation, aka globbing (that is expansion of patterns
like /usr/edit/this?.phy).
While obviously you'd rather have $NonEmptyFiles split on
newlines only (and you need to be aware that it means that your
phy filenames can't contain newline characters), and filename
generation should not be done.
Also, if phy files may also be something else than regular files
(as your -type f suggests), then you should use -prune.
Also note that it will ommit the phy files whose name start with
".". It may also fail if the list of phy files is too big.
To sum up:
NonEmptyFiles=$(
find /usr/edit/*.phy -prune -type f -size +0 -print
)
IFS='
' # newline
set -f # disable filename generation
for EachFile in $NonEmptyFiles; do
TimeStamp=$(date +%Y%m%d%H%M)
cp -- "$EachFile" "$EachFile$TimeStamp.dat"
done
But I'd rather do:
find /usr/edit/. ! -name . -prune -type f -size +0 -exec sh -c '
TimeStamp=$(date +%Y%m%d%H%M)
exec cp -- "$1" "$1$TimeStamp.dat"
' inline {} \;
Which has none of the problems described above.
--
Stéphane
.
- References:
- What Will This Return?
- From: Will
- Re: What Will This Return?
- From: Bill Marcum
- Re: What Will This Return?
- From: Will
- What Will This Return?
- Prev by Date: Need help with sed to replace a URL
- Next by Date: Re: passing arguments with getopts
- Previous by thread: Re: What Will This Return?
- Next by thread: passing arguments with getopts
- Index(es):