Extending find(1) to support -printf
Oliver Fromme
olli at lurza.secnetix.de
Mon Sep 8 13:47:23 UTC 2008
Jeremy Chadwick wrote:
> On Fri, Sep 05, 2008 at 03:12:53AM -0700, Jeremy Chadwick wrote:
> > Also, some folks on #bsdports asked why I was bothering with this in the
> > first place: mutt supports backticks to run shell commands inside of
> > a muttrc file. See "Building a list of mailboxes on the fly" below:
> >
> > http://wiki.mutt.org/?ConfigTricks
> >
> > Note the find ... -printf '%h ' method. I can accomplish (just
> > about) the same using `echo $HOME/Maildir/*`, but if I want to
> > exclude an entry, I can't use | grep -v, because mutt doesn't support
> > pipes within backticks. :-)
>
> Follow-up:
>
> mutt's backtick support does in fact respect pipes. My echo|grep -v was
> doing exactly what I requested: the grep -v was removing all output of
> the echo, since echo returned the results in a space-delimited format,
> not one per line. Hence, "mailboxes" was being executed without any
> arguments.
>
> Equally as frustrating, mutt's backtick support will only honour the
> first line of input. If a backticked command returns multiple lines,
> only the first is read; the rest are ignored.
Well, you can convert back and forth between spaces
and newlines with tr(1):
echo * | tr ' ' '\n' | grep -v whatever | tr '\n' ' '
It's not pretty, but it should work. Note that ls(1)
prints one file name per line, so you can simplify the
above line like this:
ls | grep -v whatever | tr '\n' ' '
By the way, I often use zsh in such cases. It supports
"extended globbing", for example, the wildcard expression
*~*.(gz|bz2) matches all files _except_ the ones that end
with .gz or .bz2.
Best regards
Oliver
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd
Perl is worse than Python because people wanted it worse.
-- Larry Wall
More information about the freebsd-hackers
mailing list