Suppose I have a directory containing the files
foo bar.txt
foo baz.txt
(each with a space between 'o' and 'b'). Suppose I would like to do this:
for f in *.txt; do mv ${f} `basename ${f} .txt`; done
This fails because bash expands *.txt
to
foo bar.txt foo baz.txt
instead of
foo\ bar.txt foo\ baz.txt
i.e. properly escaped as if I had used tab completion.
How can I get bash to properly escape its output?