From the course: Linux: Shells and Processes
About Linux shells - Linux Tutorial
From the course: Linux: Shells and Processes
About Linux shells
- [Instructor] When you use the keyword to type commands into a terminal window, those commands are translated by the shell into ones and zeros, and then sent as a kernel, which processes them. When the kernel finishes it sends the data back to the shell, which translates the ones and zeros back into text that makes sense to humans, which is displayed by the terminal on the screen. For this video, we're going to focus on the interpreter portion, which is the shell. A shell allows you to execute operating system commands. When a command is entered, the shell checks to see if it's a built-in command first, this means a command that is built into the shell executable. If so the shell executes it. If it's not built into the shell, it will check to see if as an alias of another command, which is configured by the user or the system administrator. Think of an alias as a shortcut. If it's not a built-in and it's not an alias, it will look for the command in a short list of directories on the disk. This list is stored in a variable called path and can be changed. If it finds the command in one of those directories, it executes it. If it doesn't find it, it will say command not found. This is the process that the shell goes through each time you type in a command. There are different shells included with different Linux distributions. In fact, you can install a different shell that may match your workflow better. When using shells, interactively, such as when typing in commands to manage an operating system the differences between shells may be small. One shell may have more built-in commands than another, or features such as automatic command option completion. The differences become more pronounced when creating shell scripts. A shell script has a text file containing multiple commands stitch together with logical conditions. A shell script is essentially a program written by the user to automate tasks. One shell may have conditional statements missing in another. Another shell may have more advanced pattern matching or more advanced string person functions. Most of these features only matter if you're writing shell scripts. There is a standard for operating systems called POSIX. POSIX is a standard designed to maintain compatibility between operating systems, mostly Unix like operating systems. Concerning shells, the standard defines the base functionality that all POSIX compliant shells include. If you want your shell scripts to be portable across different shells, it may be advantageous to write them in a POSIX compliant manner. Let's talk for a moment about the different shells available. One of the first shelves for Unix like operating systems was the Bourne shell, which was created by Steven Bourne in 1977. It's fairly basic and is also POSIX compliant. The Bourne shell is considered the lowest common denominator in Linux shells. If you want to ensure your shell script will run on most, any Linux system, you can write it for the Bourne shell. Because the Bourne shell was one of the earliest created its command name is simply sh. The next shell we'll look at is the C Shell. Displaying a bit of humor it is named C shell or CSH because it resembles the C language. It was created by Bill Joy, one of the founders of Sun Microsystems. The Bourne shell, which already existed won out in popularity and I don't recommend that you write shell scripts in CSH as they won't be compatible with most modern shells. Continuing with the corny naming scheme, the KornShell spelled with a K or ksh for short was created in 1983 and included job control and command history, which this course focuses on. So we'll talk about those items later. It also included more advanced conditional statements. Six years later, Brian Fox kept the playful naming scheme going and introduced Bash, which is short for Bourne Again Shell. The original born show was a good shell, but lack of many features introduced in the C Shell and the KornShell. Bash was an attempt to rectify this situation. Bash includes all of the original functionality of the Bourne shell, most of the additions in the KornShell and C Shell as well as additional functionality of its own. Bash is probably the default shell in more Unix like operating systems than any other. Most systems now run at least Bash Version 4. If started with the correct options, Bash is mostly POSIX compliant. Another popular shell is Dash. Dash is a Debian version of the Almquist or ASH Shell from NetBSD Unix. ASH was created by Kenneth Almquist in the late eighties. His biggest claim to fame is that it's smaller and uses less memory than Bash, and this faster, both of which are true. Dash is POSIX compliant. Generally ASH used on Debian for interactive sessions and Dash with a D is used to run shell scripts because of its speed and memory efficiency. The last shell we'll talk about is the Z shell or ZSH. ZSH has virtually identical features to Bash, but as enhanced in several ways, including better command and option completion and better pattern matching with advanced extended globs. It also has spell correction. If you misspell a command, it will ask you if you meant a different one. ZSH is generally considered the most powerful shell on Linux, but you also give up some backwards compatibility. You can have multiple shells installed at once, of course, so there's nothing wrong with trying them all. Most of these shells can be installed using DNF, for instance, to install ZSH you type in suda space, DNF space, install space, dash Y space, ZSH and hit enter. Enter your password when prompted. Just because you installed the shell doesn't mean that you're using it. To change your shell, run the change shell command and follow the prompts. Be sure to type in the whole path of the shell when prompted. Type in C H S H, and hit enter. And then for the path, type in /bin/ZSH and hit enter again and enter your password. To use the new shell, you'll have the log out and back in again. There are a lot of interesting shell options in Linux. For interactive use, you can try out the different shells to see which one you like. However, if you create shell scripts, the choice of a shell becomes very important as the syntax built-in design elements change depending on what shell you choose. Each shell has specific features to that shell, and you need to make sure that you call the appropriate shell for your script. Shell scripts written for one shell may not be compatible with another. I would recommend that at this time, keep using Bash and later explore other shells. For the rest of this course, I'll be using the Bash shell. Change back to it using the same method.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
About Linux shells6m 21s
-
About Linux terminals1m 50s
-
(Locked)
Shell pathname tricks7m 7s
-
(Locked)
Shell history tricks3m 29s
-
(Locked)
Configure shell history6m 59s
-
(Locked)
Variables and shell environment5m 33s
-
(Locked)
Make shell variables persistent6m 48s
-
(Locked)
Pattern matching with globs5m 9s
-
(Locked)
Globs exercise6m 42s
-
(Locked)
Pattern matching with extended globs6m 25s
-
(Locked)
Extended glob exercise4m 22s
-
-
-
-
-