How to correctly expand a file name with spaces as a variable within double quotes in Bash?

45 Views Asked by At

Minimal example:

f="/tmp/a file"
cmd="cat \"$f\""

set -x

$cmd

How do I correctly handle $f here such that cmd becomes cat "/tmp/a file" (double or single quote).

cmd="cat '$f'" also doesn't work.

0

There are 0 best solutions below