Sistemi UNIX - Lo shell Sistemas UNIX  -Shell UNIX-System - SHELL Systèmes UNIX - Le shell Sistema UNIX: El shell

Introduction to the shell

The command interpreter is the interface between the user and the operating system, hence its name "shell".

The shell, a shell between the OS and the user

The shell therefore acts as an intermediary between the operating system and the user using command lines entered by the latter. Its role consists of reading the command line, interpreting its meaning, executing the command, and then returning the result via the outputs.

The shell is an executable file responsible for interpreting commands, transmitting them to the system, and returning the result. There are several shells, the most common being sh (called the "Bourne shell"), bash ("Bourne again shell"), csh ("C Shell"), Tcsh ("Tenex C shell"), ksh ("Korn shell"),and zsh ("Zero shell"). Their name generally matches the name of the executable.

Each user has a default shell, which will be launched when a command prompt is opened. The default shell is specified in the configuration file /etc/passwd in the last field of the line corresponding to the user. It is possible to change the shell during a session simply by executing the corresponding executable file, for example:

/bin/bash

Command prompt window (prompt)

The shell is initialized by reading its overall configuration (in a file of the directory /etc/), followed by reading the user's own configuration (in a hidden file the name of which starts with a dot, located in the basic user directory, i.e. /home/user_name/.configuration_file). Then, a command prompt window or prompt is displayed as follows:

machine:/directory/current$
By default, for most shells, the prompt consists of the name of the machine, followed by a colon (:), the current directory, then a character indicating the type of user connected:
  • "$" specifies a normal user
  • "#" specifies the administrator, called "root"

The command line concept

A command line is a character string representing a command corresponding to an executable system file or shell command along with optional arguments (parameters):

ls -al /home/jf/
In the above command, ls is the name of the command, -al and /home/jean-francois/ are arguments. Arguments beginning with - are called options. Generally, for each command there are a certain number of options which can be detailed by entering one of the following commands:
command --help
command -?
man command

Standard input-output

Once a command is run, a process is created. This process then opens three flows:

  • stdin, called the standard input, where the process will read the input data. By default stdin refers to the keyboard; STDIN is identified by the number 0;
  • stdout, called standard output, where the process will write the output data. By default, stdin refers to the screen; STDOUT is identified by the number 1;
  • stderr, called standard error, where the process will write error messages. By default, stderr refers to the screen. STDERR is identified by the number 2;

standard input-output: STDOUT, STDIN, STDERR

By default, whenever a program is run data is read from the keyboard and the program sends its output and errors to the screen. However, it is also possible to read data from any input device, even a file, and send the output to a display device, a file, etc.

Redirections

Like any Unix type system, Linux has mechanisms which make it possible to redirect the standard input-output to files.

So, using the ">" character makes it possible to redirect the standard output of a command on the left to the file located on the right:

ls -al /home/jf/ > toto.txt
echo "Toto" > /etc/myconfigurationfile
The following command is equivalent to a copy of the files:
cat toto > toto2
The purpose of the ">" redirection is to create a new file. So, if a file with the same name already exists it will be deleted. The following command simply creates an empty file:
> file
Using the double character ">>" makes it possible to add the standard output to the file, i.e. add the output after the file without deleting it.

In the same way, the "<" character indicates a redirection of the standard input. The following command sends the content of the toto.txt file to the input of the command cat, the only purpose of which is to display the content on the standard output (example not useful, but instructive):

cat < toto.txt

Finally, using the "<<" redirection makes it possible to read on the standard input, until the string located to the right is found. In the following example, the standard input will be read until the word STOP is found, and then the result will be displayed:

cat << STOP

Communication pipes

Pipes are a communication mechanism specific to all UNIX systems. A pipe, symbolised by a vertical bar ("|" character), makes it possible to assign the standard output of one command to the standard input of another, like a pipe enabling communication between the standard input of one command with the standard output of another one.

In the following example, the standard output of the command ls -al is sent to the program sort, which is responsible for sorting the results in alphabetical order:

ls -al | sort

This makes it possible to connect a certain number of commands through successive pipes. In the example below, the command displays all the files in the current directory, selects the lines containing the word "zip" (using the grep command), and counts the total number of lines:

ls -l | grep zip | wc -l


Last update on Thursday October 16, 2008 02:43:15 PM.This document entitled « UNIX system - The shell » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.
Best answers for « UNIX system The shell » in :
Introduction to UNIX systems Show The UNIX system The Unix system is a multi-user, multi tasking operating system which means that it allows a single or multiprocessor computer to simultaneously execute several programs by one or several users. It has one or several command...
UNIX Commands Show Table of the main UNIX commands Unix Commands Description Options ls lists the content of a directory -a Displays all files, including hidden files -I Displays a...
Solaris and Open-Solaris ShowSolaris and Open-Solaris Solaris was initially based on 4.1BSD (developed by Sun), but now is based on UNIX system V fourth version (Solaris 2- Sun OS5). Consider that Solaris an Open-Solaris don’t belong anymore to the BSD...
[Shell]Create a file having a specific size ShowShell]Create a file having a specific size The dd command allows you to create "empty" file of desired size, creating these arbitrary heavy files, may be useful for testing purposes. Use command below: dd if=/dev/zero of=file_to...
Replacing Variables in Bash/shell ShowReplacing Variables in Bash/shell Intro: Expression:Defininition Intro: First of all make sure that you the variable is defined before replacing it, or in other cases determine that it is not empty, and to initialize with a default...
Download SSH Secure Shell ShowSSH secure shell for workstations is a flexible client SSH allowing to connect in a secured way to remote applications. http://www.commentcamarche.net/faq/images/NHc6wz5jOYBhPXTis.png
Download Ext2 Installable File System ShowIf you currently have Windows running and you realize that you need some files for your work which you have stored on an Ext2 volume of your Linux installation, you no longer have to shut down Windows and boot Linux! Furthermore, Windows will now...
Download Vista Live Shell Pack - Pink ShowIf you want to have Vista on your computer but your shape is not rather powerful or if simply you cannot have to be paid this version yet? Then resolution is to change the appearance of your good old XP. Vista Live Shell Pack is a topic of office...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...
Operating system ShowDescription of the operating system For a computer to be able to operate a computer programme (sometimes known as application or software), the machine must be able to perform a certain number of preparatory operations to ensure exchange between...
Connecting the computer to a HIFI sound system ShowWhy connect a computer to a sound system? These days, computers provide sound quality that is as good as hifi sound systems. It is possible to use them to listen to music, in particular thanks to mp3 files that provide sound quality that is...