Flux rss

Linux - The shell

Introduction to the shell

The command interpreter is the interface between the user and the operating system, hence the 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 thanks to command lines that are entered by the latter. Its role consists in reading the command line, interpreting its meaning, carry out the command, and then return the result via the outputs.

The shell is an executable file responsible for interpreting the commands, transmitting them to the system, and returning the result. Ther are several shells, the most common being sh (called "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 upon opening of a command prompt. The default shell is specified in the dans 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 by simply executing the corresponding executable file, for example:

/bin/bash

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 whose name starts with a dot, located in the basic user directory, i.e. /home/user_name/.configuration_file). Then, a prompt is displayed as follows:

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

The command line concept

A command line is a chain of characters representing a command which corresponds to an executable file of the system or rather a shell command as well as optional arguments (parameters):

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

Standard input-output

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

  • stdin, called standard input, in which case the process reads the input data. By default, stdin refers to the keyboard; STDIN is identified by the number 0;
  • stdout, called standard output, in which case the process writes the output data. By default, stdin refers to the screen; STDOUT is identified by the number 1;
  • stderr, called standard error, in which case the process writes the 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, the data are therefore read from the keyboard, and the program sends its output and its errors to the screen. However, it is also possible to read data from any input device, even from a file, and to 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.

Using the character ">" therefore 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. In case a file already exists with the same name, such file 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 an essentially similar manner, the character "<" indicates a redirection of the standard input. The following command sends the content of the file toto.txt with the command cat, whose only purpose 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 chain located to the right is found. In the following example, the standard input is read until the word STOP is found, and then, the result is displayed:

cat << STOP

Communication pipes

The pipes are a special communication mechanism of all UNIX systems. A piple, symbolised by a vertical bar (character "|"), makes it possible to assign the standard output of a command to the standard input of another, like a pipe allow communication between the standard input of a 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 result 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 files of the current directory, selects the lines containing the word "zip" (thanks to the command grep), and counts the total number of lines:

ls -l | grep zip | wc -l
This document entitled « Linux - 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.

Résultats pour Linux The shell

Problem in linux shell script Hello, kindly answer my question. question is: write a shell script in Linux to shift all characters in a file forward by five characters .(Thus "a" becomes "f"). faithfully syfi en.kioskea.net/forum/affich-33215-problem-in-linux-shell-script
Html code in shell script.......... Hello, I want to share one of article of a recent magazine to write html code in shell script.......... any title Our content information goes here this is written in shell script as... en.kioskea.net/forum/affich-17105-html-code-in-shell-script
Linux - Commands Command Description DOS equivalent ls lists the content of a directory dir cd change of directory cd cd .. parent directory cd.. mkdir creates a new directory md rmdir eliminates a directory deltree cp copy of a file copy, xcopy mv moves a file move... en.kioskea.net/linux/lincomm.php3

Résultats pour Linux The shell

GIT for WindowsGIT for Windows GIT is the acronym of GNU Interactive tools. It is a file system browser for handling various and large software projects with shell facilities to ease the work most notably for Linux operating system. However GIT... en.kioskea.net/faq/sujet-499-git-for-windows
Log in remotely with SSH (Linux)Log in remotely with SSH (Linux) The commands below are relevant only if you have an existing account on the PC you want to connect and that a SSH server is installed. When using Linux the syntax is quite simple as the client part is... en.kioskea.net/faq/sujet-604-log-in-remotely-with-ssh-linux
Using an USB memory key under LinuxUsing an USB memory key under Linux Automatic setup based upon version used Mandriva Fedora Core Debian & consort Manual setup Automatic setup based upon version used Follow the procedure below to set up automatically your USB... en.kioskea.net/faq/sujet-702-using-an-usb-memory-key-under-linux

Résultats pour Linux The shell

How to change IP address from command promptHello, Is there any way to change IP address of computer from Command prompt? I use WinXP as OS and I would like to know if I can change IP from Command prompt Please help me out. en.kioskea.net/forum/affich-13513-how-to-change-ip-address-from-command-prompt
Cut big folder filesHello, I just encountered this problem when i cut and paste a DVD folder like 7GB, the first time work quickly. But he second time after that it won't move the files except creating a folder on the destination partition and seem to hang there...... en.kioskea.net/forum/affich-4721-cut-big-folder-files
Shell scriptHi I have a text file named information.txt which contains information about Oracle Instances, I want to fetch data's from that text file and want to display an output using shell script. i.e. when I execute that shell script ,it should read all... en.kioskea.net/forum/affich-4477-shell-script

Résultats pour Linux The shell

Download Driver Ati Radeon Catalyst Linux x86To drive Ati Radeon Catalyst Linux x86 8.7 is a driver devoted to the cards Radeon HD of series following:X2900, 2600, on 2400, X1950, X1900, X1800, X1650, X1600, X1550, X1300, X1050, X850, X700, X600, X550, X300, 9800, 9700, X9600, X9550, X9500,... en.kioskea.net/telecharger/telecharger-850-driver-ati-radeon-catalyst-linux-x86
Download Avira AntiVir Personal free for Linux / FreeBSD / OpenBSD / SolarisFor Linux / FreeBSD / OpenBSD / Solaris Avira AntiVir PersonalEdition Classic is a very good and free antivirus which reliably protects your private computer against dangerous viruses, worms, Trojans, rootkits and costly dialers. en.kioskea.net/telecharger/telecharger-110-avira-antivir-personal-free-for-linux-freebsd-openbsd-solaris
Download Damn Small LinuxWhat does it happen of your ancient PC when you think it is obsolete? Here is the resolution which will enrapture the unhappy possessors of the old processors, "Damn Small".It is a distribution of Linux conceived to be light because she can work on... en.kioskea.net/telecharger/telecharger-304-damn-small-linux

Résultats pour Linux The shell

UNIX system - The shell The command interpreter is the interface between the user and the operating system, hence its name "shell". The shell therefore acts as an intermediary between the operating system and the user using command lines entered by the latter. Its role... en.kioskea.net/unix/unix-shell.php3
Linux - The Vi editor Despite its very limited ergonomics, Vi i is one of the most popular text editors texte under Unix type systems (with Emacs and pico). Under Linux, there is a free version of Vi called Vim (Vi Improved). Vi (pronounced vee-eye) is an editor that is... en.kioskea.net/linux/linvi.php3
Linux - Compiling the kernel In this article, compiling the kernel under Linux is explained. The following explanations are based on version 2.4.20 of kernel, i.e. the most recent version of the kernel at the time this article was written (March 2003). The sources of the most... en.kioskea.net/linux/linkernel.php3