Is it a bug?exec "cd"

$ 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

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

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

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.

On 2009-11-12, OZAWA Sakuro [email protected] 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

2009/11/12 OZAWA Sakuro [email protected]:

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

Introduction

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

Cheers

robert