Changing directory does not work in shell script

linux, shell

Solution

If you run your script with

`./scriptname`

you are opening a sub-shell where the commands of the script are executed. Changing directory in that sub-shell has no effect on the working directory of the shell that you call your script from. If instead you type

`source ./scriptname`

you should get the desired result.

Problem

I am stuck in changing the directory in a shell script in linux. ``` #!/bin/sh cd /driver ``` The above does not change the directory. Shell is running in its own context so it can not provide linux terminal with changed drive (into driver) but if I give cd /driver ls It gives the proper output of `ls` in driver directory again comes out of `driver directory` Can anybody help me to get terminal with actually changed path `(into driver)`.

Original source

Related problems