The shell is a special program used as an interface between the user and the heart of the LINUX operating system, a program called the kernel. The kernel is loaded into memory at boot-up and manages the system until shutdown. It creates and controls processes, manages memory, file systems, communications, etc. All other programs, including the shell program, reside out on the disk. The kernel loads those programs into memory, executes them, and cleans up the system when they terminate. The shell is a utility program that starts up when you log in and it interprets commands that are typed either at the command line (the prompt on the screen) or in a script file.

New users typically spend most of their time using the shell interactively. If a user types the same set of commands on a regular basis though, he would find it useful to automate those tasks by putting the commands in a script file and allowing the shell to execute that script. A script is analagous to a DOS batch file. More sophisticated scripts contain programming constructs for making decisions, looping, file testing, etc. When executing commands from within a script, the user has in fact begun to use the shell as a programming language.

Let's look a bit at different shells before we keep going, because they're going to affect some of the material coming up. If it seems confusing that Linux offers many different shells, just accept it as an effect of evolution. Shells have been developed over time, and you can now choose the one that best suits your way of working. Some of the shells available on Linux are:

    bash - Bourne Again shell. The most commonly used (and most powerful) shell on Linux. POSIX-compliant, compatible with Bourne shell, created and distributed by the GNU project (Free Software Foundation). Offers command-line editing, history substitution, and Bourne Shell compatibility.
    csh - C shell. Developed at Berkeley. Mostly compatible with the Bourne shell for interactive use, but has a very different interface for programming. Does not offer command-line editing, although it does have a sophisticated alternative called history substitution.
    ksh - Korn shell. Perhaps the most popular on Unix systems generally, and the first to introduce modern shell techniques (including some borrowed from the C shell) into the Bourne shell. Compatible with Bourne shell. Offers command-line editing.
    sh - Bourne shell. The original shell. Does not offer command-line editing.
    tcsh - Enhanced C shell. Offers command-line editing.
    zsh - Z shell. Compatible with Bourne shell. Offers command-line editing.

The popular and supported shells on most unix systems are the Bourne shell (written by S. Bourne at AT&T), the C shell (written by William Joy at Berkeley), and the Korn shell (written by David Korn at AT&T).

Try the following command to find out what your shell is. It prints out the full pathname where the shell is located. Don't forget to type the dollar sign:
$ echo $SHELL

You are probably running bash, the Bourne Again Shell. If you're running something else, this might be a good time to change to bash. It's powerful, POSIX-compliant, well-supported, and very popular on Linux.

Apart from interpreting commands and executing them, a shell also serves to customize a user's working environment. This is normally done by setting what are called variables. The statements which set these variables can be saved in files that are read by the shell. Such files are called shell initialization files and they typically contain definitions for setting terminal characteristics and window charactertistics, variables that define the search path, the appearance of the prompts, the terminal type, variables required by the shell to locate specific applications and programming libraries within the filesystem, as well as other things.

Variables are of 2 types with regards to their scope: shell and environment. Shell variables are known only to the shell in which they are defined while environment variables are passed down and inherited by processes created by the shell. This distinction is analagous to the one between local and global variables in common programming languages. Some shell variables are special in that they are created automatically when the shell starts up. Apart from such shell-defined variables, there are also user-defined shell variables. A user may create a variable of any name and assign it any value. Users may also define the scope of the variables they create (in other words, they can create both shell as well as environment variables).

Some Important Variables

HOME - Your home directory is the top of your personal branch in the file system, and is usually designated by your username, i.e. /{path}/{username}. The value of the variable HOME is the pathname of your home directory. The command cd without arguments always returns you to $HOME. In all shells except sh, the tilde (~) symbol used in filename expansion, expands to the value of this variable. For example ~/myfile is equivalent to $HOME/myfile. Also, ~{username} is equivalent to the $HOME directory of user username.

PATH - The PATH variable lists the set of directories that the shell looks in to find the commands that you enter on the command line. (For the C shell family, the shell variable path takes its value from PATH.) If the path is set incorrectly, some commands may not be found. If you enter a command with a relative or absolute pathname, the shell will only search that pathname for it, and not refer to PATH.

SHELL - The SHELL variable stores the name of the shell program.

Ultima modificare: marți, 2 mai 2023, 17:02