cat $(echo this\\ list)

Seems like it should be the same as

cat this\ list

but it isn't.

I know that I can use

cat "$(echo this\\ list)"

but then I can't echo multiple files into cat.

Why doesn't the first command work?

closed as unclear what you're asking by Kusalananda, Stephen Rauch, Jeff Schaller, Anthon, GAD3R Oct 6 '17 at 21:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    ...what are you trying to accomplish? Also don't use backticks, use $( ... ) command substitution instead. – Jesse_b Oct 6 '17 at 19:20
  • You are obviously trying to solve some sort of problem, but you are going about it in a very odd way. Edit your question to describe the actual problem or situation. – Kusalananda Oct 6 '17 at 19:21
  • I don't have a practical use for it, I'm just looking for an explanation as to why it works this way. I'll edit my post to remove the backticks – sam Oct 6 '17 at 19:22
  • Do you have a file in your PWD with the filename ./this\ list? – Jesse_b Oct 6 '17 at 19:23
  • 1
    This seems to be an XY problem. What is the issue you are trying to solve? – Kusalananda Oct 6 '17 at 19:27

What happens can be seen with set -x:

:> set -x
:> cat $(echo this\\ list)
++ echo 'this\' list
+ cat 'this\' list

:> cat this\ list
+ cat 'this list'

The difference is that 'this\' list is two arguments i.e. cat tries to read a file this\ and another file list but 'this list' ist just a single argument i.e. a different file name.

You need:

:> cat "$(echo this\ list)"
++ echo 'this list'
+ cat 'this list'

Not the answer you're looking for? Browse other questions tagged or ask your own question.