# Re: Is it a bug?exec "cd"

**URL:** <https://www.ruby-forum.com/t/re-is-it-a-bug-exec-cd/178774>\
**Category:** Ruby\
**Created:** [November 11, 2009, 3:19am UTC](https://www.ruby-forum.com/t/re-is-it-a-bug-exec-cd/178774 "2009-11-11T03:19:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wkm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/258eb7/32.png) [@wkm](https://www.ruby-forum.com/u/wkm)\
**Post date:** [November 11, 2009, 3:19am UTC](https://www.ruby-forum.com/t/re-is-it-a-bug-exec-cd/178774/1 "2009-11-11T03:19:58Z")

</div>

‘cd’ isn’t actually a program. (typically; OS X seems to have it setup  
as a super obscure shell script)

Note:

> [wkm@zanoccio ~]$ which cd  
> /usr/bin/which: no cd in (/usr/kerberos/bin://bin:/usr/local/bin:/bin:/usr/bin:/home/wiktor/bin)

It’s one of the interpreted commands of the shell you’re using.

---

<div class="post-metadata">

**Author:** ![wkm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/258eb7/32.png) [@wkm](https://www.ruby-forum.com/u/wkm)\
**Post date:** [November 11, 2009, 9:07pm UTC](https://www.ruby-forum.com/t/re-is-it-a-bug-exec-cd/178774/2 "2009-11-11T21:07:38Z")

</div>

Ah ?

~ $\> which cd  
/usr/bin/cd

Under Leopard

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

---

<div class="post-metadata">

**Author:** ![wkm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/258eb7/32.png) [@wkm](https://www.ruby-forum.com/u/wkm)\
**Post date:** [November 11, 2009, 9:24pm UTC](https://www.ruby-forum.com/t/re-is-it-a-bug-exec-cd/178774/3 "2009-11-11T21:24:01Z")

</div>

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

> [Note: parts of this message were removed to make it a legal post.]
> 
> Ah ?
> 
> ~ $\> which cd  
> /usr/bin/cd
> 
> Under Leopard

builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+“$@”}

Doesn’t mean it’ll actually DO anything.

When you execute a command, your shell forks into a parent process (your  
shell) and a child process. The child process then executes the  
command.  
The child process could, in theory, change _its_ directory – but it  
can’t  
change the directory of the parent process:

$ pwd  
/tmp  
$ /usr/bin/cd /  
$ pwd  
/tmp

I have no idea why that command exists.

(I also have no idea why they use the ${1+“$@”} idiom, since it’s been  
irrelevant on virtually everything for years, and certainly never made  
any difference on any FreeBSD or Mac OS X shell.)

-s
