Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Oct 2003 12:00:13 -0600
From:      Steve D <groups@xscd.com>
To:        FreeBSD <freebsd-questions@freebsd.org>
Subject:   Re: Fwd: Help: tar & find
Message-ID:  <200310231200.13278.groups@xscd.com>
In-Reply-To: <20031023153118.GF39601@happy-idiot-talk.infracaninophile.co.uk>
References:  <7F19C442-0513-11D8-8F40-000393801C60@g-it.ca> <200310230825.20546.groups@xscd.com> <20031023153118.GF39601@happy-idiot-talk.infracaninophile.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
Steve D <groups@xscd.com> 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 <m.seaman@infracaninophile.co.uk> 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>
   ~/tmp/test> echo "$(find . -xdev -type f -iname "*.bak" | sed "s/\(^.*$\)/'\1'/")"
'./filename with spaces.bak'
'./file two.bak'
'./file4.BAK'
   ~/tmp/test>

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
----------------------------------------------------------------



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200310231200.13278.groups>