0

Look at the following code:

ECHO A2
MKDIR -v  /tmp/"My Batch Script File Assignment"
ECHO

ECHO A3
CD "/tmp/My Batch Script File Assignment"
PWD
ECHO

can anyone tell me why the cd command under ECHO A3 isn't working. The following PWD command reports that the working directory changes to /tmp. But I am wanting to changing to the "My Batch Script File Assignment". Any one know why it is not dong this.

Gabe
  • 84,912
  • 12
  • 139
  • 238
batsta13
  • 549
  • 2
  • 12
  • 26

1 Answers1

2

I'm assuming you are using bash on OS X.

Unlike the other commands in your "script", the change directory (cd) command must be in lower case because it needs to be the shell builtin cd, not /usr/bin/cd (whose purpose escapes me).

The other commands "work" using all caps because paths and file names on OS X are case insensitive (by default anyway), so the shell finds the normal lower case commands on your PATH and invokes them. That doesn't work for CD. You need to use cd.

So:

MKDIR invokes /bin/mkdir (ok)
ECHO invokes /bin/echo (ok)
PWD invokes /bin/pwd (ok)
CD invokes /usr/bin/cd (not ok, need to use shell builtin cd)

David T. Pierson
  • 681
  • 4
  • 10
  • +1 `CD` doesn't work for me, but `cd` does. The other commands work fine in caps. [Here's what `CD` is](http://superuser.com/questions/69869/what-does-the-command-cd-do). – Wiseguy Apr 06 '12 at 02:57
  • The only real purpose of `/usr/bin/cd` is to be able to `exec` the command in order to get the exit code to find out if it's possible to change to a directory. – Gabe Apr 06 '12 at 04:01