# Dir.chdir

**URL:** <https://rubytalk.org/t/dir-chdir/4137>\
**Category:** ruby-talk\
**Created:** [15 January 2003 07:58 UTC](https://rubytalk.org/t/dir-chdir/4137 "2003-01-15T07:58:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhoujing](https://avatars.discourse-cdn.com/v4/letter/z/dc4da7/32.png) [@Zhoujing](https://rubytalk.org/u/Zhoujing)\
**Post date:** [15 January 2003 07:58 UTC](https://rubytalk.org/t/dir-chdir/4137/1 "2003-01-15T07:58:00Z")

</div>

It seems that the class method “Dir.chdir” can’t be used to implemnt  
the Unix command cd, because it can only change the working directory  
of the current process. Is that right?

Can someone suggest a good way to do the same thing as the Unix cd  
command?

Thanks.

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [15 January 2003 08:05 UTC](https://rubytalk.org/t/dir-chdir/4137/2 "2003-01-15T08:05:51Z")

</div>

Hi,

> **···**
>
> In message “Dir.chdir” on 03/01/15, TOTO [zhoujing@comp.nus.edu.sg](mailto:zhoujing@comp.nus.edu.sg) writes:
> 
> > It seems that the class method “Dir.chdir” can’t be used to implemnt  
> > the Unix command cd, because it can only change the working directory  
> > of the current process. Is that right?
> > 
> > Can someone suggest a good way to do the same thing as the Unix cd  
> > command?
> 
> Unfortunately, there’s no way to change other process’s current  
> working directory from outside. ‘the Unix cd command’ is a shell  
> builtin.
> 
> ```
> matz.
> 
> ```

---

<div class="post-metadata">

**Author:** ![gabriele\_renzi4](https://avatars.discourse-cdn.com/v4/letter/g/e36b37/32.png) [@gabriele\_renzi4](https://rubytalk.org/u/gabriele_renzi4)\
**Post date:** [15 January 2003 21:40 UTC](https://rubytalk.org/t/dir-chdir/4137/3 "2003-01-15T21:40:02Z")

</div>

> It seems that the class method “Dir.chdir” can’t be used to implemnt  
> the Unix command cd, because it can only change the working directory  
> of the current process. Is that right?
> 
> Can someone suggest a good way to do the same thing as the Unix cd  
> command?

they are the same, actually.  
$PWD is an internal variable of the shell, the same way as in ruby.

> **···**
>
> On 14 Jan 2003 23:54:51 -0800, zhoujing@comp.nus.edu.sg (TOTO) wrote:
> 
> > Thanks.
