Bash
Some shells other than Bash are :
sh (Bourne shell) - earliest shell developed by Unix in 1970's. Not frequently used today
bash (Bourne again shell) - improved version of the sh shell. One of the most popular shells used today and is widely used today on most Linux distributions.
csh (C shell) - Was developed for BSD Unix platform. Uses syntax very similar to the C programming language.
tsch (tsch shell) - A csh shell that has been improved. Default for most free BSD systems today.
zsh (Z shell) - Improved version of the old bash shell
ksh (Korn shell) - Very early shell developed early on, similar to the C shell
Default shell
When we first boot into a Linux system, a default shell is automatically loaded. To find out which shell is currently active, type the command echo $SHELL
at the terminal.
If you get an output of bin/bash
, that means you are currently in the Bash shell.
To switch to a different shell, simply type in the name of the shell command e.g. zsh to switch to the Z Shell. Note that this will only work if the Zsh shell has been installed on that Linux box.
BASH
Most users that think of BASH think of it as a prompt and a command line. That is BASH in interactive mode. BASH can also run in non-interactive mode, as when executing scripts. We can use scripts to automate certain logic. Scripts are basically lists of commands (just like the ones you can type on the command line), but stored in a file. When a script is executed, all these commands are (generally) executed sequentially, one after another.
We'll start with the basics in aninteractive shell. Once you're familiar with those, you can put them together in scripts.
You should make yourself familiar with the man and apropos commands on the shell. They will be vital to your self-tutoring.
$ man man
$ man apropos
In this guide, the$at the beginning of a line represents your BASH prompt. Traditionally, a shell prompt either ends with$,%or#. If it ends with$, this indicates a shell that's compatible with the Bourne shell (such as a POSIX shell, or a Korn shell, or Bash). If it ends with%, this indicates aC shell(csh or tcsh); this guide does not cover C shell. If it ends with#, this indicates that the shell is running as the system's superuser account (root), and that you should be extra careful.
Your actual BASH prompt will probably be much longer than$. Prompts are often highly individualized.
Themancommand stands for "manual"; it opens documentation (so-called "man pages") on various topics. You use it by running the commandman [topic]at the BASH prompt, where[topic]is the name of the "page" you wish to read. Note that many of these "pages" are considerably longer than one printed page; nevertheless, the name persists. Each command (application) on your system is likely to have a man page. There are pages for other things too, such as system calls or specific configuration files. In this guide, we will only be covering commands.
Note that if you're looking for information on BASH built-ins (commands provided by BASH, not by external applications) you should look inman bashinstead. BASH's manual is extensive and detailed. It is an excellent reference, albeit more technical than this guide.
Bash also offers ahelpcommand which contains brief summaries of its built-in commands (which we'll discuss in depth later on).
$ help
$ help read
Interactive mode v/s Script mode
Interactive mode: A mode of operation where a prompt asks you for one command at a time.
Script: A file that contains a sequence of commands to execute one after the other.