From owner-freebsd-questions@FreeBSD.ORG Mon Jun 30 22:30:16 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3EE468E5 for ; Mon, 30 Jun 2014 22:30:16 +0000 (UTC) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F107F2CBE for ; Mon, 30 Jun 2014 22:30:15 +0000 (UTC) Received: from r56.edvax.de (port-92-195-69-249.dynamic.qsc.de [92.195.69.249]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 0E5EF3CC53; Tue, 1 Jul 2014 00:30:13 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id s5UMUDCj003460; Tue, 1 Jul 2014 00:30:13 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Tue, 1 Jul 2014 00:30:13 +0200 From: Polytropon To: Gary Kline Subject: Re: long string using find and "-exec ls -ls" to find part-of filename Message-Id: <20140701003013.f068eb05.freebsd@edvax.de> In-Reply-To: <20140630215534.GA28552@ethic.thought.org> References: <20140630045605.GA11147@ethic.thought.org> <53B0EFF2.80205@calorieking.com> <20140630053004.GB16901@ethic.thought.org> <20140630064044.GA25085@ethic.thought.org> <20140630230316.44ec3257.freebsd@edvax.de> <20140630214506.GA1606@holstein.holy.cow> <20140630215534.GA28552@ethic.thought.org> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing List X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jun 2014 22:30:16 -0000 On Mon, 30 Jun 2014 14:55:34 -0700, Gary Kline wrote: > how about whitespace? ls -lsi appears as two cmds, so would > it work as you have with backtics? > > find ... | xargs -n 1 `ls -lsi` Erm... this looks wrong. Either find or ls, but both... except of course you want a ls -lsi output for each item found by find... :-) In case of whitespaces in filenames, you need to use at least "..." (double quotes), that's why using a variable here is probably the safer solution. Note that the whitespace has a special meaning to the shell: it's the standard field separator, separating commands and command line arguments. The output separator of ls and find is a newline, so the following should work for files with spaces: #!/bin/sh OLD_IFS=$IFS IFS=" " ls -lsi *.tar.gz *.tgz | while read F; do some_command "$F" done IFS=$OLD_IFS First, IFS is set to newline. Then ls with the desired options is run. Its results are separated by a newline. They are piped to the while read construct which reads one line = one result item at a time, executing the command. The double quotes make sure that each result (which can contain spaces) is provided as _one_ command line argument. Finally, IFS is restored. But the articles I mentioned before do cover this quite compli- cated topic much better. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...