Background:
My plan is this: I would like to take a hard drive from a Windows box and slap it into a linux box, find every file of a certain extention on the drive, and copy it to a backup directory. I have been trying to do this with a csh script and a foreach loop. A vague pseudo code of this seemingly easy script looks like this:
foreach thingie ( list of files )
copy $thingie /whatever/backup
end
And that's all I keep thinking it should take. But the problem is this.
I have the command:
Code:
find /customers/drive | grep -i jpg
for example, and this outputs:
Code:
/customers/drive/directory/file01.jpg
/customers/drive/directory/sub/file02.jpg
/customers/drive/directory/sub/file03.jpg
etc. BUT when I put it into the foreach loop, the foreach loop interprets spaces in directory names and files incorrectly. So what I end up with is the output of find giving me
Code:
/customers/drive/Documents and Settings/bob/pics/pic01.jpg
BUT since the foreach intereprets things as
foreach var (thing1 thing2 thing3 thing4)
it sees the output of foreach var (`find /customers/drive | grep -i jpg`) as
thing1 = /customers/drive/Documets
thing2 = and
thing3 = Settings/bob/pics/pic01.jpg
And naturally gives me a "cannot stat file 'and' - file cannot be copied".
So basically, is there a way to tell foreach not to interpret spaces in lines as new items in it's list? To tell it the delimeter for a new entry in the list is a newline?
Full script is basically this (so far):
Code:
foreach thing (`find /customers/drive | grep -i jpg`)
cp -backup=t $thing /backup
end
Things I've tried so far: using sed to "escape" the space character via changing the parenthetical phrase for the foreach condition to say:
Code:
foreach thing (`find /customers/drive | grep -i jpg | sed 's/\ /\\ /g'`)
which didn't work either - if you do it from the command line, it gives you files like /customers/drive/Documets\ and\ settings/bob/pic01.jpg, but foreach still sees them as being breaks at the spaces.
Alternatively, is there an easier way to do this?
Thanks for all help, sorry this was so long, trying to give as much info as I could.
~Wx