I have a space in one of the directory names. I want to list a file under it from a bash script. Here is my script:fpath=${HOME}/\New Folder\/foobar.txtecho fpath=(${fpath})#fpath=${HOME}/${fname}ls ${fpath}The output for this script is:fpath=(/Users/<username>/New Folder/foobar.txt)ls: /Users/<username>/New Folder/foobar.txt: No such file or directoryBut when is list the file on my shell it exists:$ ls /Users/<username>/New Folder/foobar.txt/Users/<username>/New Folder/foobar.txtIs there a way I can get ls to display the path from my script?
Spaces for variables in bash script
bash;shell script;quoting;variable substitution
Just remove the inner quoted double-quotes:fpath=${HOME}/New Folder/foobar.txtSince the complete variable contents are contained in double-quotes, you don't need to do it a second time. The reason it works from the CLI is that Bash evaluates the quotes first. It fails in the variable because the backslash-escaped quotes are treated as a literal part of the directory path.