Wednesday, November 13, 2024

macos – Can Bash case-insensitive matching for executables in $PATH be disabled?

No it cannot!

If you check it with ls -ldi /usr/bin/grep /usr/bin/Grep you will
see that both exist on your filesystem but they are the same inode. Funny detail is that in fact the filesystem stores a case sensitive string, only one of the 16 combinations of GREP writing ( trick to see it: cd /usr/bin ; echo [gG][rR][eE][pP] ). Some people talk of case preserving FS but it’s just a way to increase confusion.

This is not a bash typical problem. Any shell will show you the same truth.
This is a filesystem “feature”¹.
This type of floating naming of files leads to source codes which can
create a file named “A” and later on open it as “a”, thus creating bugs, vulnerabilities and crapwares.

The way to get rid of this problem, is:

  1. make a complete backup copy of the
    root filesystem on an external disk formatted as a “case-sensitive” one.
    An excellent tool for this task is Carbon Copy Cloner ( you can achieve
    the same perfect copy with rsync but with an arm long list of
    arguments ).
  2. Reboot on this external backup.
  3. Reformat the original root filesystem as a “case-sensitive” one.
  4. Make the symmetric copy from your external disk toward your original one.

( Tested and applied on many versions of macOS since > 20 years ).


¹)  Brief history of filesystems: case insensitive filesystems
    were created to help people who might experience problems
    with the use of uppercase.
    Since more than ½ century all Unix OS are running on
    case sensitive filesystems.
    Nowadays, most filesystems are even more open to the use of
    numerous alphabets, with many more differences than just
    lower case versus upper case and implement correctly UTF-8
    ( https://en.wikipedia.org/wiki/UTF-8 ).

Related Articles

Latest Articles