Learning Linux Part 4/15: The shell explained
Alright, part 4 of the series, which is mostly dedicated to the shell environment.
- What is a shell?
- Various shells
- Basic functions of bash
- Default settings in the shell
- Boot files of the shell
The shell is a text based interface between de user and the linux Kernel. The shell is capable of translate commands of the user into system calls for the computer.
The linux platform has several different shells available. The most common shells are:
Bourne Shell
The original Unix shell is the Bourne Shell, which was developed by Steve Bourne. This shell resides in most of the time at /bin/sh
C-shell
The C-Shell which was developed later then the Bourne Shell and was considered the improved version of the Bourne Shell. It is easier to work with, mostly because of functions like `code completion` and `history`.. The path of this shell is : /bin/csh
Korn-Shell
The Korn Shell combines the best of previous shells. Most people use it to stay compatible with the Bourne shell and have the easy functions of the C-Shell. This path of this shell is : /bin/ksh
Bourne Again Shell
The Bourne Again shell (bash) is an extension on the Bourne Shell. It is backwards compatible with the Bourne Shell. This is the most popular shell on most linux computers, because of it's easy to use features like:
- code completion
- wildcards support
- history
- redirection
- etc.
tcsh
A shell which is pretty popular under C developers, because tcsh has an internal programming language which is very similair to C itselves. Features are very common to bash.
pdksh
Public Domain Korn Shell is a variant of the original Korn Shell.
ash & zsh
Ash en Zsh are some small shells that are not very common, so we wont pay attention to them this time.
SHELL USAGE TYPES
The shell can be used in different kind of ways:
- Interactive shell - This shell is used when you open a terminal and a certain shell is loaded.
- Non-interactive shell - When you start a shell script or a command, the non interactive shell is used.
- Login shell - If you login, this shell is used, based on the information that resides in /etc/passwd .
- Subshell - A shell started within a shell ( ie. when you starting bash inside bash )
- Remote shell (rsh) - This shell is used in a network environment, to login from one machine to another. Due to some serious security issues, this shell isn't used any more.
- Secure shell (ssh) - A shell which makes a secure encrypted connection from one computer to the other.
INPUT AND OUTPUT (I/O)
Input and Output on linux is based on the fact that every device of the system is treated as a file. So there is no difference between the treatment of a harddisk or a modem.
Linux has a standard input, standard output and standard error. The standard input is in most cases the combination of the keyboard and the monitor. Standard output and standard error are also being showed on the monitor these days.
BACKGROUND AND FOREGROUND
Linux gives you the possibility to start a process in the background. This can be done by adding an ampersand to the command.
For example: if you would like to search for the file "hostname" on the linux system, but dont want to wait untill the process is finished, then you can use the following command.
find / -name "hostname" &
To regain control on the find process, you can use the internal command "fg" (foreground). To put it back to the background you can use the "bg" command.
Processes that are running on the background or foregrond can be listed by using the "jobs" command.
root@overloader:/# find / -name "*.php" &
[1] 6001
root@overloader:/# jobs
[1]+ Running find / -name "*.php" &
root@overloader:/#
QUOTING
Sometimes you don't want characters to be substituted. In that case you can make use of escaping, which is really no more then putting a backslash in front of the character OR put the text between single quotes.
For example:
echo \* \* \* \* \* \*
or
echo '* * * * * *'
Will display in both ways "* * * * * *" on your commandline.
When you are starting a shell, a couple of files are being scanned for default settings. These settings are used to define the environment.
/etc/profile and .bash_profile
This file defines all settings which apply to users of bash. For example, the prompt, the PATH and aliases can be defined here. After this file is processed, the system looks for a file called ~/.bash_profile to apply user specific settings.
/etc/bashrc and ~/.bashrc
While the /etc/profile is being used every time when you login, /etc/bashrc is being read every time when you start a new subshell. The ~/.bashrc file is the personalised file of /etc/bashrc.
~/.bash_logout
This file is called when you logout and can be usefull for cleaning up temporary files, or something like that.