Date: Tue, 1 Jul 2014 00:30:13 +0200 From: Polytropon <freebsd@edvax.de> To: Gary Kline <kline@thought.org> Cc: FreeBSD Mailing List <freebsd-questions@freebsd.org> 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> <CA%2Bg%2BBvg1=o71ObOpbh4ry-=unj2HOjjmcQHX1DOeAfwyhLu=QQ@mail.gmail.com> <20140630053004.GB16901@ethic.thought.org> <CA%2Bg%2BBvh%2BDk0iYCjbGKVt59-nfDoCFQ6qmArrJu7ueaT7VzDi1g@mail.gmail.com> <20140630064044.GA25085@ethic.thought.org> <20140630230316.44ec3257.freebsd@edvax.de> <20140630214506.GA1606@holstein.holy.cow> <20140630215534.GA28552@ethic.thought.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140701003013.f068eb05.freebsd>