What happens when you type on a Unix shell


What happens when you type (not necessary a command) on a unix shell? More specifically what happens in the background as you type on the shell?

You have to understand computer systems architecture to really know what is happening, but basically your computer has 2 levels, 1 the hardware, and 2 software.

Hardware is broken down into a lot of things, but the most important to your question are the keyboard and the screen. So if you're typing on the keyboard, there must be some software involved to display what you're typing on the screen. In modern systems (like this web page), it is handled by (at least) 2 layers of software.

The Operating System is a bottom level set of sub-systems that connect all the pieces together as (roughly) services, i.e. typing service, disk service, network service, display service, and many other more technical peices, often related to these things 'talking to each other.

The ultimate level of software (user facing) for displaying what you're typing in a web page is provided by the browser software you are using. The OS passes-on the values of the key presses, mouse clicks, etc to the browser, and the browser decides what to do with them.

So the Unix command line is 2 layers too, the OS level, coordinating services (keyboard to screen). To get to the point that your keystrokes have any meeting to the OS, you have to launch an application that is designed to recieve and display inputs and outputs. When you're typing on the command line, the OS is sending keypresses onto your shell program, bash, ksh, zsh, others.

It's not until you hit the enter key that the shell things it has to do something, AND basically, the only thing it knows to do when you press the enter key, is to scan back and read what you have typed in. It will assume that you know what you're doing and that what you have typed are valid commands supported by your system. It also has many rules about what to do if it encounters text that is considered features of the shell, like environment variables (${MyName}), pipes | which help connect 2 programs to send data from left-hand side program to right-hand program, AND many other features.

So, you didn't want to know what is happening in the shell specifically, so the answer is, the OS is getting activity from the keyboard, and because you have to run a shell (or other program) to accept input from the keyboard, the OS passes those keypress values into the running program.

(Seeing the nature of your other posted questions, my apologies if this is too simple-minded ;-( , but ...)

I hope this helps.