I\'m using Bash on macOS X and I\'d like to create a simple executable script file that would change to another directory when it\'s run. However, the path to that director
A single backslash works for me:
ry4an@ry4an-mini:~$ mkdir "My Code"
ry4an@ry4an-mini:~$ vi todir.sh
ry4an@ry4an-mini:~$ . todir.sh
ry4an@ry4an-mini:My Code$ cat ../todir.sh
#!/bin/sh
cd ~/My\ Code
Are you sure the problem isn't that your shell script is changing directory in its subshell, but then you're back in the main shell (and original dir) when done? I avoided that by using . to run the script in the current shell, though most folks would just use an alias for this. The spaces could be a red herring.