./go_back: line 1: cd~-: command not found
there must be a space between cd and ~-
I don't know how works putty; and I don't know what "global variables" are (except against local ones in functions).
Bash has some variables that it creates, such as BASH_VERSION, SHELLOPTS, PWD, and so on.
A script always runs in a subshell, it will never change the directory of the main shell.
A script is a child process, it can't change any variable of its parent.
try to add some pwd
commands into your script, you'll see it changed directory.
it's the same as
var="foo"; echo "mainshell pwd is $(pwd), and var = \"$var\""; (echo "subshell pwd is $(pwd), and var = \"$var\""; echo "changing directory, and var's value"; cd /bin; var="bar"; echo "subshell pwd is now $(pwd), and var = \"$var\""); echo "mainshell pwd is still $(pwd), and var = \"$var\""
typed on the command line: what's between '(' and ')' is executed in a subshell.