(This is a simplest working example of something in a much messier context.)
I have a directory
d with files
1.txt 2.txt 3.txt 4.wav.
My current directory is somewhere else.
ls d reports
1.txt 2.txt 3.txt 4.wav, as it should.
But I want only
1.txt 2.txt 3.txt, so I try
But that prepends a
d/ to each filename:
d/1.txt d/2.txt d/3.txt, because the shell expanded the
ls saw it.
To get my desired
1.txt 2.txt 3.txt, I could
ls d | grep txt, or
ls d/*.txt | xargs basename -a, or even spawn a new shell:
(cd d; ls *.txt). Is there a better way, less clunky, less vulnerable to gotchas and corner cases, to filter the output of