Is there a quick way to check in terminal that the terminal command pwd returns the correct capitalization of the path?

Note that if you do cd ~/desktop then pwd would tell you that your path is /Users/foo/desktop rather than the correct /Users/foo/Desktop.

EDIT: Motivation: build systems need a way to check this early on, otherwise it's really hard to debug. An unsuspecting user uses a wrong capitalisation, starts a build, gets errors that are very puzzling.

EDIT2: Silently accepting incorrectly capitalised input for cd is the standard behaviour of bash on an HFS+ file system, and thus for the vast majority of OSX users. Then, pwd is a bash builtin, and it simply takes the content of the path stack of the shell (typos included).

  • Why would you not want to do cd ~/Desktop then pwd would tell you /Users/user/Desktop/ – Brick Jun 1 '16 at 12:38
  • 1
    this is to make a build system more robust. I'll edit the question with more details – Dima Pasechnik Jun 1 '16 at 14:24
  • 1) How can pwd return anything but the correct capitalization of the current directory? 2) How can you cd ~/desktop and go to /Users/foo/Desktop unless you have a symlink or something? This question makes no sense. – Allan Jun 1 '16 at 14:42
  • 1
    @Allan : try what I say in the question, on a case-insensitive filesystem! You will be surprised. No, you do not need symlinks or anything. It just works (TM :-)) - and shoots you in the foot along the way. – Dima Pasechnik Jun 1 '16 at 16:30
  • 2
    @Allan I suppose 95% of Apple users do. By default Apple ships machines with HFS+ filesystems (i.e. case insensitive). – Dima Pasechnik Jun 1 '16 at 17:07

Use /bin/pwd

cd ~/desktop
/bin/pwd -P

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .