I am trying to change a directory to home/developer. I used cd home/developer in my shell script. After executing script it is again coming to original directory,where I executed shell script.


When you start your script a new process is created that only inherits your environment. Your current environment stays as it is. You can start your script like this if you want to change the current directory from a script:

. script.sh


source script.sh

The . (source is the long version of .) will evaluate the script in the current environment so it might be altered.

When a script is run using source it runs within the existing shell, any variables created or modified by the script will remain available after the script completes. In contrast if the script is run just as script.sh, then a separate subshell (with a completely separate set of variables) would be spawned to run the script.


  • If I run the mentioned command,terminal is getting close. – Sujatha Jul 29 '13 at 7:30
  • 2
    @Sujatha Can you post your script on paste.ubuntu.com ? I suspect that you have exit command inside the script. If so, it is normal. – Radu Rădeanu Jul 29 '13 at 7:32
  • Thank you. It is working fine. I have uncommented the exit command. – Sujatha Jul 29 '13 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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