Is it a bug?exec "cd"

H

Haoqi Haoqi

$ 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
 
D

Dan Rumney

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top