Steve D <[EMAIL PROTECTED]> wrote:

> Would the following approach also work? (Have sed surround each
> item returned by the find command with single quotes?)
> ---
> #! /bin/bash
> set +x
> TAR_DIR=/home/tarbackups;
> FILES_DIR=/home/common;
> tar --remove-files -cvzpf $TAR_DIR/bak_files_`date +%F`.tar.gz\
>     `find $FILES_DIR -xdev -type f -iname "*.bak" | sed "s/\(^.*$\)/'\1'/"`;
> or the backticks in the last line replaced with the newer
> alternative "$()":
>     "$( find $FILES_DIR -xdev -type f -iname "*.bak" | sed "s/\(^.*$\)/'\1'/" )" ;

Matthew Seaman <[EMAIL PROTECTED]> responded:
> You've apparently got double quotes inside a double quoted string.
> That doesn't work.
> Trying to enclose the output of find in quote marks will sort of
> work, but it's generally found to be flaky.  Especially when the
> filenames you're dealing with also contain quotation marks of various
> types or return characters.  This is exactly why the '-print0'
> primitive for find(1) was invented: it puts out a list of file names
> separated by ascii NULL characters, which is one of the two ascii
> characters you can't get in a filename. (The other is '/' -- the
> directory separator).


Thank you Matthew for this information. Interestingly, the double quotes
inside double quotes seems to work on my machine (using
/usr/local/bin/bash), perhaps because the contents inside the "$( )" 
are processed in a subshell? Output of terminal session follows:

   ~/tmp/test> touch 'filename with spaces.bak' 'file two.bak' file3.txt file4.BAK
   ~/tmp/test> ls -l
total 0
-rw-r--r--  1 xscd  xscd  0 Oct 23 11:45 file two.bak
-rw-r--r--  1 xscd  xscd  0 Oct 23 11:45 file3.txt
-rw-r--r--  1 xscd  xscd  0 Oct 23 11:45 file4.BAK
-rw-r--r--  1 xscd  xscd  0 Oct 23 11:45 filename with spaces.bak
   ~/tmp/test> echo "$(find . -xdev -type f -iname "*.bak" | sed "s/\(^.*$\)/'\1'/")"
'./filename with spaces.bak'
'./file two.bak'

Now because of your response I am motivated to read and learn more
about find's -print0 option and about xargs. Thank you.

Steve D
Portales, NM US

Civilization is a process in search of humanity. -Eli Khamarov

[EMAIL PROTECTED] mailing list
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to