why doesn’t this work on a bash command line:
cat `echo "'filename with spaces'"`
It produces these errors:
cat: 'filename: No such file or directory
cat: with: No such file or directory
cat: spaces': No such file or directory
in other words, the single quotes in the string output by the command in the back-ticks is not parsed in the normal way. Does anyone know a way I can make this work? Or perhaps a better approach?
I’ve used cat and echo here as a simple example, but this behavior is rather annoying if, for example, you wish to process a list of files whose names are stored in a file.
Using
set -xwill be instructive.What you would need is
But if what you’re doing is reading newline-delimited file names from a file you should use a
whilereadconstruct, like this:If you don’t want to process each file but instead want to treat them all at once, use