3

I made a very simple script

#!/bin/bash
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.

vdegenne
  • 1,746

1 Answers1

4

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.

DopeGhoti
  • 76,081