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)
.
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.
do "source script_name". It will change the directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With