I have a file in /usr/bin called code, which contains the following:
cd ~/Documents/Code
However, when I run it by simply executing
$ code
Nothing happens. Why is this, and how can I make code perform as I would like?
When you run code, a new process is spawned to execute that script. The script changes directories (for his process) and returns. Your original shell's process still has the same working directory. Child processes cannot manipulate the state of their parent.
A better way to accomplish this would be with an alias. Add this to your ~/.bashrc:
alias code='cd ~/Documents/Code'
. $(which code), but there are better ways to cd, one is mentioned by Jonathon.