1

I'm launching my script from echo $PWD ---> /x. I want my script to change my current directory. So my script contains +- this :

cd /y
exit 0

However, when my script ends, I'm stils in echo $PWD ---> /x. I'd like to be in /y. Why doesn't it work ?

I'm launching my script simply by doing : [myScriptName]

3

That's because your shell starts another shell to run your script. The second shell changes its working directory and then exits to the first shell, which never changed its directory.

To make your current shell run the script, call it this way:

. scriptname

(notice the dot). Of course, you'll have to take out that exit 0.

You can also write a shell function. See ksh(1).

  • It works, ty. What's the purpose of the dot ? – user1058398 Nov 19 '13 at 13:16
  • 2
    @user1058398 . is the same as source. – terdon Nov 19 '13 at 14:01

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.