I would like to escape path with white space which works fine when I use it directly like this:
$ printf '%q' "/path/to/first dir/dir/"
/path/to/first\ dir/dir/
When I use a variable instead of string though the return is a string with no white space whatsoever:
$ testpath="/path/to/first dir/dir/" && printf '%q' $testpath
/path/to/firstdir/dir/
Is there any way to escape white space in a path with printf and a variable. Or any other simple solution without using awk/sed/regex?