Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
possible duplicate of Why doesn't "cd" work in a shell script? – muru Dec 4 '14 at 18:16
up vote 10 down vote accepted

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:




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, then a separate subshell (with a completely separate set of variables) would be spawned to run the script.


share|improve this answer
If I run the mentioned command,terminal is getting close. – Sujatha Jul 29 '13 at 7:30
@Sujatha Can you post your script on ? 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 posting your answer, you agree to the privacy policy and terms of service.

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