Why is the terminal case-sensitive?

When I do – CD .. instead of cd ..
it gives me error saying –

CD: command not found

Why is the terminal case sensitive when it comes to linux commands? I mean you should be able to execute the command either with “all uppercase” or “all lowercase” characters.

I know it is due to some reason, but I am just curious.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Ultimately, it was an arbitrary choice made by the creators of Unix over four decades ago now. They could have chosen to make things case-insensitive like the creators of MS-DOS did a decade later, but that has its disadvantages, too.

It’s too deeply embedded in *ix culture to change now. The case sensitive filesystem issue brought up by eppesuig is only part of it. macOS systems — which are Unix-based — typically have case-insensitive (but case-preserving) file systems, so on such systems commands external to the shell are in fact treated case-insensitively. But, builtins like cd remain case-sensitive.

Even with a case-insensitive filesystem, the history of things conspires against your wishes, Hussain. If I type ls on my Mac, I get a colorized directory listing. If I type LS instead, /bin/ls still runs, but the listing isn’t colorized because the alias that adds the -C flag is case-sensitive.

Best just get used to it. If you can, learn to like it.

Method 2

This is not a “terminal” problem, it is a file system feature. How should the shell look for your commands on the (always case sensitive) file system?

Method 3

The technical systems that I use and respect are almost exclusively case-sensitive: be it OS or programming language or anything else.

The exceptions I could think of right now is the HTML tags and some implementations of SQL, and the Ada programming language.

Even in those cases, I think there are strong tendencies to actually write HTML tags in lowercase, and the SQL query semantics in uppercase (and parameters capitalized). (Correct me if I’m wrong.) As for Ada, the Emacs mode will correct you if you for example type a lowercase procedure name, although that won’t matter when compiling. So, even when there is case-insensitiveness, it seems people agree it’s a bad idea.

The reason is that you get much more expressive power with case-sensitiveness. Not only quantitatively – CD is one, but CD, Cd, cD, and cd are four – but more importantly, you can express purpose, emphasis, etc. using upper- and lowercase sensibly; also, when programming, you’ll enhance readability.

Intuitively, it is clear that you don’t read hi and HI the same way!

But, to give you a computer world example, in the programming language Ada (from the 1980s), the first line of a procedure code block could look like this:

procedure body P(SCB : in out Semaphore_Control_Block) is

as you see, the procedure and parameter names are capitalized, as are datatypes, everything else is lowercase. Also note that the “all uppercase” parameter name tells us that it is an acronym. Now, compare this to

procedure body p(scb : in out semaphore_control_block) is

This is possible, as Ada is case-insensitive (or, to be exact, the compiler will change it to the way in my first example, but of course won’t change your code). Or, how about:

PROCedure body P(Scb : IN Out semaphore_CONTROL_BLOCK) iS

That one is a bit ridiculous, I know; but someone would be stupid enough to write it that way (well, perhaps not). Point is, a case sensitive system will not only force people to be consistent, they will also be helped by it (readability) and use it to their advantage (the acronym example above).

Method 4

It’s no more or less strange than the fact that we have an upper and lower case alphabet to start with. If you look in /usr/bin, you’ll notice a (very) few executables exploit capitalization.

A case sensitive namespace is not just twice as big as an insensitive one — the difference grows exponentially with word length. Eg, using 26 characters, there are 26^3 (17576) different possibilities in three letters; using 52 (2 * 26) characters there are 52^3=140608. An open namespace is a good thing 😉

Method 5

The concept of “upper/lower” case can be (and is indeed) a locale specific thing, which, as any other design complication should be pushed as close to the usage point as possible in the application stack, not be a part of the core.

Having case sensitive environment allows to wrap it into case insensitive environment, but not other way around.

Method 6

It is not the terminal, it is the file-system. Or in the case of cd (cd is a shell built in) the shell, that is case sensitive.

It could have been possible (at least with ASCII), to make is case insensitive. This is harder with the now used unicode (whether two characters are the same, may depend on local).

What to do about it

  • Live with it.
  • Try these shell options. They give a compromise, and make things easier, without introducing all of the problems of case insensitivity.
    • shopt -s nocaseglob #this is in my ~/.bashrc
    • shopt -s nocasematch #this would also be in ~/.bashrc
    • set completion-ignore-case on #this is in my ~/.inputrc

Method 7

As a starting point, the reason this question was asked, and the reason you will find much discussion on it if you Google the subject, is that case sensitivity makes it harder for “normal” people to learn and use a programming language or command line interface.

Case sensitivity has its origins in the low power of computers in the past. To make things case insensitive required one additional parsing operation before the command was fed to the interpreter or to a compiler before its execution and early designers were not prepared to waste the computer’s power for the convenience of case sensitivity.

I believe there are a number of incorrect assertions in the comments made above. Firstly, psychologists will tell you that humans don’t automatically discriminate between a word written in upper or lower case letters or even a combination of the two in terms of the word’s meaning. Case is used in normal expressive languages to convey an additional meaning. For example, the use of a capital letter starting a word in a sentence, indicates it is most probably a proper noun. Capital letters are also used to give prose structure. For example, a capital letter, is used to indicate the beginning of a sentence. But “Word” and “word” are viewed by the human mind as meaning the same.

The creators of DOS and of ADA and Pascal, to name a few, appreciated that case sensitivity was an additional burden on the beginner. Later, text editors in “Integrated Development Environments” (IDEs), recognising a reserve word, could recast that word such that it was consistent with style anyway; plus display it in a different colour to make the word stand out. So the argument that case sensitivity makes for more readable code is fallacious. It doesn’t to “normal” people. It simply adds an unnecessary and sometimes confusing layer to an already demanding task.

Java is an extreme example of a very poor language from the point of view of ease of use by a beginner. It enforces strict case sensitivity but, stupidly, will allow the programmer to have two functions, both with the same name, but which are actually different functions by virtue of the fact one has a different set of arguments to the other. Indeed, Java is such an abortion of a language that when universities moved from teaching Pascal syntax to students, undertaking non-computer science courses, the pass rate fell from around 70% to 40%.

So, in summary, case sensitivity came about for two reasons. One was lack of computer power. The second was that people who find their way into computer science are often on the autistic spectrum and don’t relate well to the needs of “normal” people. As a consequence, these people cannot appreciate that case sensitivity is both unnecessary and an impediment to learning and using a programming language.

Method 8

Case sensitivity is a silly idea that came about because Unix writers did not understand that ASCII is designed to be readily case insensitive. One simply ignores the leading bits. Ascii is a 7 bit coding with capital A at bit value decimal 65 1000001 and a at bit decimal 97 1100001. with the letters following alphabetically. This generated all sorts of ideas such as all keys in key value pairs should be numeric to avoid Slippers being different to slippers. Pick Multi-Value database realised this from the beginning and is case insensitive.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x