Wednesday, January 18, 2017

How the Linux Shell Works

To fully understand how the command-line interface works under Linux, you need to understand the concept of a shell. A shell is a command interpreter that allows you to type commands at the keyboard that are sent to the operating system kernel.
Linux enables you to choose from a variety of shells. As with many other aspects of Linux, you can try out several different command-line shells and choose the one that you like the best. Here’s a list of some of the more popular shells:
     sh (Bourne Shell)   The sh shell was the earliest shell, being developed for UNIX back in the late 1970s. Although not widely used on Linux systems, it is still frequently used on UNIX systems.
     bash (Bourne-Again Shell)   The bash shell is an improved version of the sh shell and is one of the most popular shells today. In fact, it’s the shell used by default on most Linux distributions. If you’re using the command-line interface on a Linux system, more than likely you’re using the bash shell.
     csh (C Shell)   The csh shell was originally developed for BSD UNIX. It uses a syntax that is very similar to C programming.
     tsch   The tsch shell is an improved version of the C Shell. It is the default shell used on FreeBSD systems.
     zsh (Z Shell)   The Z Shell is an improved version of the bash shell.
When you first boot your Linux system and log in, your default shell is loaded. You can identify which shell you’re using by entering echo $SHELL at the command prompt. The echo command is used to display text on the screen. Adding $SHELL to the echo command tells echo to display the contents of the SHELL environment variable for the currently logged-in user.
However, you’re not stuck with the default shell. If you want to switch to a different shell, simply enter the shell’s command name at the prompt. For example, if you are currently using the bash shell and want to use zsh instead, simply enter zsh at the prompt. To stop using the new shell and revert back to the original shell, enter exit.

Linux is capable of running multiple shell sessions at once. Each session can run its own programs, all simultaneously. This can be very useful if you have one program running and then need access to the command prompt. With many distributions, such as openSUSE, you simply press ALT-Fx (where x is a number from 2 to 6) to open a new session. For example, to switch to the third alternate console screen, press ALT-F3. You can then return to your original session by pressing ALT-F1.
As with Windows, you can also run terminal sessions within the Linux GUI. This is done by running a terminal program such as Konsole or GNOME Terminal. To run multiple command-line sessions, simply open two or more terminal windows. Each shell session runs its programs independently of the other sessions.
This can also be accomplished in a second way. While you’re within the Linux GUI, press CTRL-ALT-Fx (where x is a number from 1 to 6). This will switch you to a text-based shell prompt. To switch back to your GUI environment, press ALT-F7 (on most distributions).

No comments:

Post a Comment