Ubuntu – How to change directory using script


I have this script

cd /home/user/somedir

it works as expected, but I would like this script to transport me to /home/user/somedir, but I stay in the same dir.

How to write script that will transport me (in gnome-terminal) to /home/user/somedir?

Best Answer

You need to source your script. If not it will be run in a separate subshell, changing the working directory of the subshell but not of the shell you run it in.

To source it :

. myfile.sh


source myfile.sh

You can read more here