Can't escape spaces in variable name

I trying to deal with spaces in directory names. As an example:

drive=/mnt/g; export drive
mydir="$drive/directory with spaces in name"
echo "$mydir"

The result:

/mnt/g/directory with spaces in name

Which of course, blows up on use, as bash sees this as separate arguments. The desired result would be something like:

"/mnt/g/directory with spaces in name"

as a single argument for subsequent processing (moves, copies, or whatever). I had thought that a double quote does the trick. Obviously not. Bash keeps eating the double quotes. Can someone point me to the proper procedure for handling variables with embedded spaces?

I'm using the Windows subsystem for Linux in Windows 10, but Ubuntu 20.04 LTS has the same behavior, so I'm assuming what works for one, will work for both. (Something with ILS maybe, IDK.)


Your code is fine! You have spaces in variable that why will be spaces out of echo as well. So if you want to use a parameter that contains spaces you have to put between quotes like you do.

example:

command "${variable1}" "${variable2}"