# Is it a bug?exec "cd"

**URL:** <https://www.ruby-forum.com/t/is-it-a-bug-exec-cd/178773>\
**Category:** Ruby\
**Created:** [November 11, 2009, 2:51am UTC](https://www.ruby-forum.com/t/is-it-a-bug-exec-cd/178773 "2009-11-11T02:51:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 11, 2009, 2:51am UTC](https://www.ruby-forum.com/t/is-it-a-bug-exec-cd/178773/1 "2009-11-11T02:51:47Z")

</div>

## $ cat into.rb exec “cd /tmp” $ ruby into.rb into.rb:1:in `exec’: No such file or directory - cd /tmp (Errno::ENOENT) from into.rb:1

exec “cd anything” as the same result error.how to exec “cd”?thanks

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 11, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/is-it-a-bug-exec-cd/178773/2 "2009-11-11T21:30:27Z")

</div>

> Ah ?
> 
> ~ $\> which cd  
> /usr/bin/cd
> 
> Under Leopard

That may be the case under Leopard, but for many users of Linux, ‘cd’  
is a command that is built into the ‘bash’ shell.

As a result, a call to the command ‘cd’ using exec wont work. This is  
probably one of the reasons that languages such as Ruby include  
functions for precisely this operation.

The message

into.rb:1:in `exec’: No such file or directory - cd /tmp  
(Errno::ENOENT)

is complaining that there is ‘No such file or directory’ as ‘cd’…  
not ‘/tmp’. You can confirm this:

$ cat into.rb  
exec “cd”  
$ ruby into.rb  
into.rb:1:in `exec’: No such file or directory - cd (Errno::ENOENT)  
from into.rb:1

Dan

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 12, 2009, 3:59am UTC](https://www.ruby-forum.com/t/is-it-a-bug-exec-cd/178773/3 "2009-11-12T03:59:06Z")

</div>

See the last section of the document below to know why external ‘cd’  
exists.

[http://www.opengroup.org/onlinepubs/009695399/utilities/xcu\_chap01.html](http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap01.html)

A very rare use of it is to test if a directory can be chdir-able.

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 12, 2009, 4:55am UTC](https://www.ruby-forum.com/t/is-it-a-bug-exec-cd/178773/4 "2009-11-12T04:55:52Z")

</div>

On 2009-11-12, OZAWA Sakuro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> A very rare use of it is to test if a directory can be chdir-able.

That actually sort of makes sense. Neat!

-s

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 12, 2009, 1:04pm UTC](https://www.ruby-forum.com/t/is-it-a-bug-exec-cd/178773/5 "2009-11-12T13:04:02Z")

</div>

2009/11/12 OZAWA Sakuro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> See the last section of the document below to know why external ‘cd’ exists.
> 
> [Introduction](http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap01.html)
> 
> A very rare use of it is to test if a directory can be chdir-able.

Also

[http://www.opengroup.org/onlinepubs/009695399/utilities/cd.html#tag\_04\_15\_16](http://www.opengroup.org/onlinepubs/009695399/utilities/cd.html#tag_04_15_16)

Cheers

robert
