When make directories for each file with certain extension:
$ ls a.ttt b.ttt c.ttt d.ttt e.ttt $ mkdir $(ls *.ttt | cut -f 1 -d ".") $ ls a a.ttt b b.ttt c c.ttt d d.ttt e e.ttt
…everything works just fine. However if I do it for .tex files I get following results:
$ ls a.tex b.tex c.tex d.tex e.tex $ mkdir $(ls *.tex | cut -f 1 -d ".") $ ls ?[00;32mb ?[00;32mc ?[00;32md ?[00;32me ?[0m?[00;32ma a.tex b.tex c.tex d.tex e.tex
I just wanted to clean my latex directory and I get weird directory names. Why is that and how to make it work?
Advertisement
Answer
It is error prone to use output from ls
like this.
You can use:
# grab all *.tex files in an array arr=(*.tex) # replace part after DOT and create directories mkdir -p "${arr[@]//.*}"