Re: Grep and mv

From: WCB (wbarwell_at_Mungggedd.mylinuxisp.com)
Date: 07/15/05


Date: Thu, 14 Jul 2005 18:45:08 -0500

John L wrote:

>
> "WCB" <wbarwell@Mungggedd.mylinuxisp.com> wrote in message
> news:11dddoroaj154ee@corp.supernews.com...
>> rolandberry@hotmail.com wrote:
>>
>> > You know me. If you want a beginners guide then I can send you
>> > something.
>>
>> Heh! Now you know what I'm doing.
>>
>> Its not that. It looks like I have found a big bug
>> in bash. neither mv nor cp work in a for do done loop
>> or similar structures.
>> They work fine as a single line outside such.
>>
>> The one task I am trying to do seems to be stymied not by
>> lack of knowledge but by a bug.
>>
>> Take large file oec1
>> Use csplit to extract files xx00 - xxNN
>> extract new name.
>> mv xxNN newname
>>
>> move all files to indexing, searchable database
>> system with mySQL as a backend.
>>
>> Bug stops mv $i $f from working.
>
> You run: grep HCO* $i
> follower by a mv which creates a file called (say)
> HCO-September-26
>
> Next time round the loop you run the same grep but
> this time, before the command runs, the shell expands
> the HCO* to match the filename so you actually run:
> grep HCO-September-26 $i
> which presumably most times gives no output.

Well, no.

What I have is:

******
/bin/bash
# mover5

set -x

for i in xx*;
do

grep -m 1 HCO* $i > x
sed 's/^ *//' x > y
sed 's/ /-/g' y > z

This works, I get z which is my name
f=$(cat z)

This gives me $f

echo $i >> I
echo $f >> F
echo
 
I gives ...
xx06
xx07
xx08
xx09
xx10
xx100
xx101

F gives me ....
HCO-BULLETIN-OF-25-JANUARY-1962
HCO-BULLETIN-OF-1-FEBRUARY-1962
HCO-INFORMATION-LETTER-OF-1-FEBRUARY-1962
HCO-INFORMATION-LETTER-OF-3-FEBRUARY-1962-All
HCO-BULLETIN-OF-8-FEBRUARY-1962
HCO-BULLETIN-OF-29-NOVEMBER-AD12
HCO-POLICY-LETTER-OF-1-DECEMBER-1962

**************************************

So far, so good

mv $i $f >> M

Cat M gives me

mv xx06 HCO-BULLETIN-OF-25-JANUARY-1962
mv xx07 HCO-BULLETIN-OF-1-FEBRUARY-1962
mv xx08 HCO-INFORMATION-LETTER-OF-1-FEBRUARY-1962
mv xx09 HCO-INFORMATION-LETTER-OF-3-FEBRUARY-1962-All
mv xx10 HCO-BULLETIN-OF-8-FEBRUARY-1962
mv xx100 HCO-BULLETIN-OF-29-NOVEMBER-AD12
mv xx101 HCO-POLICY-LETTER-OF-1-DECEMBER-1962

This should work.
But nothing moves.

Why..

If I type mv xx06 HCO-BULLETIN-OF-25-JANUARY-1962 and hit enter
MV works

Or I can do it from a script,

#!/bin/bash

mv xx07 HCO-SOME-BLOODY-FILE

That works.

It is just in a do for done loop, there is no signal passed
to mv to do the deed. Its like typing it and not hitting enter.

done
# end

****************************

Here is a test script I wrote and ran

#1/bin/bash

 # mover3

file1="bigfile"

file2="xx08"

mv xx09 file9

mv $file2 file8

mv xx06 $file1

f10="xx10"
f100="file10"

mv $f10 $f100
  
***************************

All of these ran perfectly, outside the
for do done loop!
And... cp works the same as mv!

Great in the above script, not as cp $i $f
in a for do done loop.

Its just a big old bug is all.

The little test script above tells the tale.

The echo mv $i $f >> M file shows
everything is working fine up to that point.
  
The for do done falls flat on its face big time.

And mv does not like attempted work arounds.
(read < $f) and other attempted work arounds failed.
I screwed with stuff like this just to see what happens
"$i", {$f}, nothing seems to do anything.
appending \r doesn't. I played with it quite a bit
and its plain old broke.

Its an extremely reliable bug.
Easily reproduced.

It just seems strange to me that no one
else has run across this
Or maybe they do and I just don't know it.
I haven't found anything on google.

-- 
When I shake my killfile I can hear them buzzing.


Relevant Pages