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!

Spaces in Directory Names 1

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
CA
I am trying to execute a script which reads directory pathnames from a file and using them as options of a command. The problem is the pathnames contain spaces and the command interprets these spaces as separating multiple options instead of a single one.

Is there a "universal" way to substitute spaces for a character and have UNIX interpret them correctly?

Barring that, is there a way to do it in Solaris?

Thanks,
Jeff
 
Something like this ?
while read dir
do
YourCommand [red]"[/red]$dir[red]"[/red] YourOptions
done </path/to/listofdirs

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
use double-quotes around the dir. name variables in your script (of the ways).

Post a script if you need help.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I don't follow.

If we assume the command is something simple like "ls" and the directories are:

/directory one
/directory two
/directory the third

how would that work?

Thanks,
Jeff
 
[tt]ls [purple]"[/purple]/directory one[purple]"[/purple][/tt]

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Sorry, I guess ls is a bad example. I understand how it would work by simply putting double quotes around it, but I don't understand how the while-do loop would work.

Also, the command I am executing doesn't seem to care if things are bounded by quotes or not, it still recognizes the spaces as divisions between new options.

Jeff
 
pls post a sample code.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
The command is called ugpc. The format is

ugpc -p/dir1 -p/dir2 -p/dir3 myfile

but /dir1 is actually named /directory one..etc and the list is in dirfile (a text file)

CODE:
ugpc `sed -e 's!^!-p!' "$dirfile"` $myfile

Jeff
 
Have you tried this syntax ?

[tt]ugpc -p"$dir_file" $myfile[/tt]

Jean Pierre.
 
This command requires -p to prefix each and every directory in the list in "dirfile", so that doesn't appear to work.

Jeff
 
ok, so how are you reading the content of the 'dirfile' and invoking 'ugpc'? A sample pls!

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
As I posted above:

CODE:
ugpc `sed -e 's!^!-p!' "$dirfile"` $myfile
 
Your variable 'dirfile' contains filenames, how are they delimited ?

If the delimiter is a space, there is no way to distinguish the different filenames since they may contain spaces.
Use another delimiter, "," as example and do :
[tt]
ugcp `echo $dirfile | awk '{for (i=1; i<=NF; i++) print "-p\"" $i "\""}' FS=,` myfile[/tt]

Jean Pierre.
 
Each directory is on a separate line in the file.
 
Try...

eval gpc `sed -e 's!^!-p"!' -e 's!$!"!' "$dirfile"` $myfile
 
[tt]
ugcp `echo "$dirfile" | sed 's/\(.*\)/-p"\1"/' myfile[/tt]

Jean Pierre.
 
Something like this ?
while read dir
do
args=args" -p'$dir'"
done </path/to/listofdirs
ugpc $args myfile

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Sorry, your file list is in a file not a variable
[tt]ugcp `sed 's/\(.*\)/-p"\1"/' $dirfile` myfile [/tt]

Jean Pierre.
 
something like that?

ugpc $(sed -e 's:\(.*\):p"\1":g;s:`echo '\t'`:" :g' jmarkus.txt)

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ooops, sorry:

ugpc $(sed -e 's:\(.*\):p"\1":g;s:`echo '\n'`: :g' jmarkus.txt)

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top