1

As the title says, I'm looking for the most dependable way to detect whether a file-system is case sensitive or not, provided a given path.

In the past I've used the following dirty trick:

[ -e "/tmp" -a -e "/Tmp" ] && echo "Case insensitive" || echo "Case sensitive"

Which works because a system won't typically have both a /tmp and a /Tmp folder. This of course is hacky at best, and of no-use for arbitrary paths as it could be pointing to a device without either folder.

What I was thinking instead was doing something like getting a path's directory (which should exist) and somehow "flipping" its case (so upper case letters become lower case and vice versa), but I'm not sure how to do that either; I can flip all lower to upper, but that won't be any use if the directory's name is already all uppercase.

Anyway, I'm looking for suggestions on the best way to detect if a file-system is case sensitive or not, preferably without creating temporary files if possible.

Haravikk
  • 3,109
  • 1
  • 33
  • 46
  • You could check for a suitable regular file (creating if necessary) that the all-lowercase and all-uppercase versions of the file name refer to the same inode, if both exist (and your filesystem uses inodes; otherwise substitute whatever mechanism exists for checking if two names refer to the same file). – chepner Oct 18 '13 at 18:36
  • Unfortunately I can't do this either, as the path may not be writeable. Your inode comparison idea could still work for the path I'm provided, using both upper and lower case versions, but I wouldn't be able to distinguish these from two hard links to the same inode, it's still better than what I have so far at least! – Haravikk Mar 26 '14 at 09:45

1 Answers1

0
[ -e "${PWD^^}" ] && echo "Case insensitive" || echo "Case sensitive"

Converting string case in Bash shell scripting

Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407