From owner-freebsd-questions@FreeBSD.ORG Thu Oct 23 10:59:55 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EC9B616A4B3 for ; Thu, 23 Oct 2003 10:59:55 -0700 (PDT) Received: from enmu.edu (EM01.enmu.edu [192.94.216.103]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0D31743F93 for ; Thu, 23 Oct 2003 10:59:54 -0700 (PDT) (envelope-from groups@xscd.com) Received: from TSEH010.enmu.edu (TSEH010.enmu.edu [198.59.107.10]) by enmu.edu (Postfix) with ESMTP id 0E3B8BC190; Thu, 23 Oct 2003 11:59:47 -0600 (MDT) From: Steve D To: FreeBSD Date: Thu, 23 Oct 2003 12:00:13 -0600 User-Agent: KMail/1.5.2 References: <7F19C442-0513-11D8-8F40-000393801C60@g-it.ca> <200310230825.20546.groups@xscd.com> <20031023153118.GF39601@happy-idiot-talk.infracaninophile.co.uk> In-Reply-To: <20031023153118.GF39601@happy-idiot-talk.infracaninophile.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200310231200.13278.groups@xscd.com> Subject: Re: Fwd: Help: tar & find X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Oct 2003 17:59:56 -0000 Steve D 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 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 ----------------------------------------------------------------