Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: executing commands in directories containing specific files



On Feb 11, 10:11pm, Leonardo Barbosa wrote:
}
} I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say i
} have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux, b.aux,
} c.aux. What's the best way of doing that?

I like using the (e) flag, but it's sometimes tricky to get right on the
first try because you have to be careful to match up the parens in the
reply=(...) assignment, the quotes around the expression, the outer set
of delimiters (I used [...] below) and the parens around the whole thing:

    rm **/*.tex(.e['reply=(${REPLY:r}.aux)'])

But you can also use colon-modifiers as glob qualifiers, so if the .tex
never appears anywhere but at the end:

    rm **/*.tex(.:s/.tex/.aux)

If you've already got the filenames, say, in an array:

    texi=( $(find $HOME -type f -name '*.tex') )

Colon-modifiers work on every word in an array, so you can use the "^"
flag (rcexpandparam) like so:

    rm ${^texi:r}.aux

Or you can just use one of the loops already suggested.



Messages sorted by: Reverse Date, Date, Thread, Author