Tried to set some aliases in my .bashrc file. This one…
export alias umusic="/Volumes/180 gram/Uncompressed/"
…gets the following error…
-bash: cd: /Volumes/180: No such file or directory
…when I try “cd $umusic”.
I’ve tried various methods of escaping that whitespace in the directory name, to no avail. (180\ gram, 180%20gram, single quotes, double quotes, no quotes.) I realize the easiest solution is to rename the directory to “180gram,” but I’d like to know how to solve this particular problem.
I’m on a Mac, if that makes any difference.
Your use of the
exportcommand is makingumusican environment variable and not an alias. Theexportcommand exports environment variables named on the rest of the command line, optionally with new values. So it’s exporting an environment variable namedalias(which probably isn’t set) and one namedumusic.Given that you’re expanding an environment variable, the shell does the following substitution:
which generates the error you get because the space isn’t quoted. If instead you do:
then the expansion is
which is what you’re expecting.
However, using an environment variable for this might be still a bit too much work, since you have to quote the expansion. Instead, try this alias:
which you would run with just