(Note: after some more research I have a partial answer, but I don't like having to write the actual commands against that variable differently depending on embedded spaces or not. I'll accept better suggestions).
I like to store various work variables in bash as I am working on something. This avoids having to type it up every time and also helps when you come back to work on it some time later (stick the assignment in a localprofile.sh file and source
that later...).
I'd like to store a directory name with spaces in it. I know how to do deal with spaces in file/directory names interactively, using either quoting or \-based escaping:
$ ls -1 /Users/myuser/Library/Application\ Support/ | tail -5
iTerm2
icdd
org.videolan.vlc
pip
videosubscriptionsd
or
$ ls -1 "/Users/myuser/Library/Application Support/" | tail -5
iTerm2
icdd
org.videolan.vlc
pip
videosubscriptionsd
Now I'd like to assign that directory to a bash $dn variable and that's not working so well.
Here are some various tries. On purpose I stayed away from ~-based shell extension.
dn='/Users/myuser/Library/Application Support/'
echo ''
echo ''
echo $dn
ls -1 $dn
dn='"/Users/myuser/Library/Application Support/"'
echo ''
echo ''
echo $dn
ls -1 $dn
dn=/Users/myuser/Library/Application\ Support/
echo ''
echo ''
echo $dn
ls -1 $dn
dn="/Users/myuser/Library/Application\ Support/"
echo ''
echo ''
echo $dn
ls -1 $dn
each one of these shows a variation on ls: /Users/myuser/Library/Application\: No such file or directory