Let me elaborate on this:
When the script starts, bash creates a new process for it, and changes in the current directory affect only this process.
When you submit a script, the script is executed directly by the shell that you run without creating additional processes, so changes to the current directory are displayed in the main shell process.
So, as Ignacio pointed out, this is impossible to do.
Maxim sloyko
source share