[H-GEN] ksh scripting problem

Scott Pullen spullen at optusnet.com.au
Sat Aug 23 12:05:05 EDT 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

This is probably trivial but it is late and I can't for the life of me think
how to do it.  The environment is Solaris 8 and I would prefer to use ksh.

How do I copy files using the i-node instead of the filename?

The reason I ask is that I am using a for loop using filenames/directories
that may contain spaces.  I need to make a decision if the current entry is
a file or directory and then process accordingly.  The for loop processes
each token in the list, even if the filenames/directory names are surrounded
by double quotes.

eg the code looks something like this

for $entity in `ls $source$entry`
do
	if [[ -d $entity ]]; then
		recursively call function
	fi

	if [[ -f $entity && -r $entity ]]; then
		cp $entity $newdir$source$entry
	fi
done

 If the $source$entry has spaces in it then the above loop has some serious
problems performing the function intended. I tried writing a function that
returned the filename list with each filename surrounded by quotes but that
does not stop the tokenising of the list by the for command.  I thought of
using the i-node which prompted the above question but I can't work out how
to copy the files without using the find command which I think is
inefficient.  If that is the only was to do it then I will have to look at
the impact on the performance of the script and the box but surely there is
an easier option.  Should I just use a different looping construct that
avoids this problem and if so what is it?

Any suggestions gratefully accepted,

Cheers,

Scott.


--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list