From: Brian Candler Date: 2008-09-30T00:17:47+09:00 Subject: Re: [working directory to be changed (in terminal) by the Ru > Initially I have created an external file .sh (via ruby) with the bash > code inside, then called from the ruby script, i.e.: > > system ("'.' ./cd_#{app_name}.sh;pwd") FYI, that is the same as: system("/bin/sh","-c",". ./cd_#{app_name}.sh;pwd") In other words you're starting a new shell as a new process, and inside that new subshell you're changing directory. Ruby waits for this new shell to terminate before continuing. Therefore, if you're starting Ruby itself from a shell, then you have the following processes: initial shell -------> ruby --------> new shell The 'cd' command within the new shell affects only its own current directory, not the current directory of either Ruby or the initial shell. It's really a question of what you're trying to achieve. If you want to run a shell script with a particular current directory, then it's easy (just cd to the right directory and then start the script; you can use Dir.chdir within Ruby to do this). But Ruby can only affect the current directory of new processes which it starts, not the parent process ("initial shell" in the above diagram) which started Ruby. Only the initial shell itself can change its own current directory. -- Posted via http://www.ruby-forum.com/.