This question already has an answer here:

I made a very simple script

mkdir $1 && cd $1

when I execute

myscript test

It creates test directory but doesn't go inside just after. I don't understand why, on my fedora 27 this script works without any issue but on my debian stretch this behavior occurs. Could someone explain why I am having this bug.

marked as duplicate by steeldriver, LinuxSecurityFreak, mkc, ilkkachu bash May 1 '18 at 16:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You can and it works perfectly. But when the script is done, its environment (including its working directory) is destroyed.

Try source myscript test to execute your script as though you had typed its commands into your actual interactive shell and you working directory will have been changed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.