Using LaTeX creates a bunch of auxiliary files like foo.aux
, foo.log
, etc. Sometimes, I want to create a clean run of my document. I usually manually execute this in the terminal as
$ ls foo*
foo.tex
foo.aux
foo.log
foo.bbl
foo-blx.bib
$ rm foo{.aux,.log,.bbl,-blx.bib}
This works fine. However, it is error-prone and I don't want to accidentally erase my .tex
file. So I added this function to my ~/.bashrc
:
# Delete all non-TeX files
# invoke as: cleantex foo
# where: foo.tex, foo.aux, foo.log, etc. are files in directory
cleantex () {
if [ -n "$1"]; then
name = $(basename -s ".tex" "$1")
rm -f $name{.!(*tex),-blx.bib}
fi
}
My question is about the key line
rm -f $name{.!(*tex),-blx.bib}
that actually executes the script.
Is this line well-written? What might I improve here?
basename
are you using? I am not familiar with (and can't find) the-s
option for it. – rolfl Mar 27 '14 at 23:22man basename
has the option, as does the official documentation. Is your distribution out of date? – WChargin Mar 27 '14 at 23:26.tex
suffix if there is one. So,cleantex foo
is the same ascleantex foo.tex
. – WChargin Mar 27 '14 at 23:27basename foo.tex .tex
will producefoo
. Food for thought – rolfl Mar 27 '14 at 23:31