From the course: Unix Essential Training

Kernel and shells - Unix Tutorial

From the course: Unix Essential Training

Start my 1-month free trial

Kernel and shells

- [Instructor] In this movie, we'll learn about kernels and shells, which are an important aspect of the Unix operating environment. The kernel is the core of the operating system in Unix. It's the part that's responsible for allocating time and memory to each program. It does the fundamental management of how commands and programs conduct their work. You aren't going to need to worry about choosing a kernel. You made that choice already when you picked a version of Unix to use. Different versions have different kernels. The shell is the outer layer of the operating system. It's what we see when we open up a terminal window. We're working in the shell. It interacts with the user and we can think of it as our working environment. the shell will send requests to the kernel. The kernel will then do its job and launch programs and then the results will be returned back to the shell so that we can interact with them again. We do have the ability to choose different shells. They're all similar, but they have some slightly different features. The very first shell was called sh. It's also known as the Thompson shell because it was created by Ken Thompson. It was the primary working environment for a long time. Then in 1977, the Bourne shell was created by Stephen Bourne as a replacement for the Thompson shell. Notice that it has the exact same name, sh, short for shell. Then it starts to become more common to have choices about which shell you use. You'll notice that a lot of the names have a bit of programmer humor in them, starting with the C shell, or csh. Then there was the tcsh, the Tabbed C shell, the ksh, or Korn shell, and the bash shell, which is the Bourne-again shell. You can see how that name is a play off of the Bourne shell. The bash shell has been one of the most popular shells for the last 30 years, and it's often the default shell. It's the one that I learned on and the one that I used for many, many years until recently I started using the Z shell, instead. One of the most notable recent shells is the fish shell, or Friendly interactive shell. There are many shells besides these, I mean dozens and dozens of them. They all work in a very similar way. They're just trying to improve on the shells of the past. It's also possible to switch shells while you're working and for different users on a multi-user system to each pick the shell that they like best. It's a lot like picking a favorite flavor of ice cream. For beginners, the difference between these shells is small. A lot of the difference between them is going to be the features that are available to high-end users for tasks like advanced shell scripting. For now, you can safely stick with whatever your default shell is. Let's look at the command line. As I said, when we're inside one of these windows like this, we're inside the shell. That's the working environment that we're in. You can see actually that my window tells me up here that I'm using the Z shell, zsh. We can see that this is my default shell if I type the command echo followed by a space and a dollar sign, and then all capital S-H-E-L-L. When you hit return, it tells you the location of the shell that you're currently using. You can see that it's zsh. We also can type echo space dollar sign zero and it'll tell us our current shell. Again, it tells us zsh. Now, the default shell and the current shell don't have to be the same. We can switch shells. For example, I can type the command bash and it will switch me into the bash shell. Now on macOS, it comes up with a extra message that many of you may not see. that's because the bash shell was the default Mac shell for a long time and it has recently switched to the Z shell. So this is a message just to let users know about this change. The message is not important. What I want you to see, though, is that if I type echo space dollar sign zero, it now tells me that I'm using the bash shell. I'm inside the bash shell and whatever quirks and peculiarities it has, that's now my working environment. Let's also from here, go into ksh. Now I'm in the Korn shell, or ksh, echo dollar sign Z will tell me that. I can do tcsh. You can see that my prompt changed when I did that. I can do csh, and now I'm in the C shell, or I can do sh, I'm all the way back in that Bourne shell. Now, each time I type one of these commands, I'm actually moving into a shell within a shell. They're like layers. So right now I'm actually working inside the Bourne shell inside the C shell inside the TC shell, inside the Korn shell inside the bash shell, which is inside the Z shell. I'm several layers deep. It's a bit like inception, going one layer deeper each time. So if I type exit now, it doesn't exit out of the program, it exits out of the shell. If I type exit again, I go back another level and back another level, let's just stop and take a look and see what level we're at. I'm at ksh. I can exit again and again and now if I do echo dollar sign zero, you can see I'm back at that Z sh shell. That dash at the beginning is the indicator that I'm back at the very root. As I said before, you're probably going to stick with your default shell throughout this tutorial, whatever that may be. What I want you to understand is that the shell exists, that it's the working environment that you're in, that different users can have different default shells, and that you can change shells if you need to.

Contents