Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling spaces in paths

Status
Not open for further replies.

butterfm

Programmer
Feb 15, 2002
132
GB
Hi,

I have a tab seperated file with a number of lines in the following format :

file1 c:/some dir/temp c:/some other dir/temp

I'm trring to write a script in MKS toolkit as follows

while read filename sourcedir destdir
do
cp ${sourcedir}/${filename} ${destdir}
done < file

simple enough, except that sourcepath and destpath have spaces in the directory names and therefore I get an error.

Does anybody have any ideas how to handle teh spaces in the path names with the read command.

Thanks,
M
 
have you tried putting the directory names in double quotes?
 
This might do it.

[tt]while IFS=&quot; &quot; read filename sourcedir destdir
do
cp ${sourcedir}/${filename} ${destdir}
done < file[/tt]

The piece between the quotes is a single tab. That way it will stop treating a space as an inter field separator.

Annihilannic.
 
Hi,

It still gives an error from the mkdir and cp command due to the spaces in the paths.

This is the script:

#!/bin/ksh

SOURCE=c:/temp/reports
DEST=c:/test

cat file | grep -v '#' | while read filename source destination
do
mkdir -p &quot;${DEST}/${destination}&quot;
cp &quot;${SOURCE}/${source}/${filename}&quot; &quot;${DEST}/${destination}&quot;
done

MKSToolkit is an UNIX emulation tool that runs on windows.

Matt.
 
do the IFS=&quot;TabChar&quot; before or inside the while loop.

Hope This Help
PH.
 
Sorry the script should be

#!/bin/ksh

SOURCE=c:/temp/reports
DEST=c:/test
IFS=&quot;\t&quot;

cat file | grep -v '#' | while read filename source destination
do
mkdir -p &quot;${DEST}/${destination}&quot;
cp &quot;${SOURCE}/${source}/${filename}&quot; &quot;${DEST}/${destination}&quot;
done

Any ideas
 
Slight correction:

[tt]while IFS=&quot; &quot; read filename sourcedir destdir
do
cp &quot;${sourcedir}/${filename}&quot; &quot;${destdir}&quot;
done < file[/tt]

I forgot to quote the operands for the cp command.


Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top