This is because commands you execute from the shell are first forked off as a new process. What you do in that new process does not affect your original shell. A 'cd' command is one of the exceptions to that; it is executed by the shell process itself (or it would not have any lasting effect).
When you execute a shell script, the shell forks off another shell to interpret that script. Any 'cd' commands in that script then only affect that latter shell, so their effect expires as soon as that shell terminates (at the end of the script).
Should work without problems; the effect of the 'cd' would remain valid within the same script. The shell that had executed it would only terminate when it reaches the end of the script. After that the shell from which you invoked the script would take over again, so you won't find yourself in 'path' (presumably the XBoard source directory) anymore. But you would have no business there anyway; the make-install would already have moved the xboard binary to /usr/local/bin.
Should work without problems; the effect of the 'cd' would remain valid within the same script. The shell that had executed it would only terminate when it reaches the end of the script. After that the shell from which you invoked the script would take over again, so you won't find yourself in 'path' (presumably the XBoard source directory) anymore. But you would have no business there anyway; the make-install would already have moved the xboard binary to /usr/local/bin.
By the way in order not to confuse my builds with official ones , can I change the icon of XBoard ?
To answer the original question, you are probably using bash as your shell. Instead of writing a script, you can define a bash function (https://linuxize.com/post/bash-functions/), which doesn't spawn a new process, and would be able to change the working directory just fine.
rather than executing the file that does the CD, simply type "source <filename>" and it will execute the cd command and whatever in the SAME (current) process, so that once you source the command and do a "pwd" you will find you are in the new directory.
This works for the c-shell as I use it all the time. Can't say about the other shells although I suspect they would also do this...
Keep in mind, that bash is always picky about quoting and whitespace.
Then do logout/login or type bash if you want to test things and then try cdw on the commandline.
Type help alias for short help within bash or man bash and then /alias to search system docs.
and reload bash.
Autojump will start to remember your visited directories. Aftera directory is learned, you can "jump" to it with a few keystrokes.
If ~/my_working_dir is learned, the command