Linux Shells
A shell is a command-line interpreter that acts as an interface between the user and the operating system’s kernel. It translates human-readable commands into instructions the system can execute.
- A shell allows for interactive or non-interactive command execution.
Linux has different types of shells available, each with its own features and characteristics.
-
Bourne-Again Shell (bash)
-
C Shell (csh)
-
Korn Shell (ksh)
-
Enhanced C shell (tcsh)
-
Z Shell (zsh)
-
Check your current shell: Type
echo $SHELLin your terminal. -
List all installed shells: Run
cat /etc/shellsto see what is available on your system. -
Change your shell: Use the
chsh(change shell) command followed by the path of the shell you want to switch to.
Bash (Bourne-Again SHell)#
Bash (Bourne Again SHell) is the default command-line interpreter and scripting language for most Unix-like operating systems (such as Linux and macOS).
- It is known for its reliability and widespread compatibility for scripting.
- Before bash, some shells like sh, ksh, and csh had different capabilities. Bash came as an enhanced replacement for these shells, borrowing capabilities from all of them. This means that it has many of the features of these old shells and some of its unique abilities.
- It offers a tab completion feature, which means if you are in the middle of completing a command, you can press the tab key on your keyboard. It will automatically complete the command based on a possible match or give you multiple suggestions for completing it.
- Bash keeps a history file and logs all of your commands. You can use the up and down arrow keys to use the previous commands without typing them again. You can also type
historyto display all your previous commands.
Bash configurations are primarily managed in the ~/.bashrc file in your home directory.
The following websites provide examples of Bash scripting concepts, tutorials, examples, and cheat sheets:
- GNU Bash Reference : https://www.gnu.org/software/bash/ ↗
- Wikipedia: https://en.wikipedia.org/wiki/Bash_(Unix_shell) ↗
- Linux Config Bash Scripting Tutorial: https://linuxconfig.org/bash-scripting-tutorial ↗
- DevHints Bash Shell Programming Cheat Sheet: https://devhints.io/bash ↗
Zsh (Z Shell)#
Zsh (Z Shell) is a powerful, highly customizable UNIX command-line interpreter and scripting language.
It is a popular replacement for Bash due to its smart auto-completion, built-in spell check, shared command history, and rich plugin ecosystem
- Zsh provides advanced tab completion and is also capable of writing scripts.
- It also provides auto spell correction for the commands.
- It offers extensive customization that may make it slower than other shells.
- It also provides tab completion, command history functionality, and several other features.
Resources - https://www.zsh.org/ ↗
- https://en.wikipedia.org/wiki/Z_shell ↗
Zsh configurations are primarily managed in the~/.zshrcfile in your home directory. - Oh My Zsh ↗: The most popular community-driven framework for managing Zsh configurations.
- Prezto: A highly anticipated, modular and snappy configuration framework for Zsh.
- Powerlevel10k: A lightning-fast theme that provides instant feedback, Git integration, and beautiful status icons.
- Zinit ↗ is a fast and feature-rich plugin manager for the Zsh Unix shell. It is designed to handle plugins, snippets, and themes efficiently, offering specialized features like “Turbo mode” to significantly speed up shell startup times.
Fish (Friendly Interactive Shell)#
A modern, user-friendly shell that focuses on out-of-the-box features like syntax highlighting and web-based configuration.
- It offers a very simple syntax, which is feasible for beginner users.
- Unlike bash, it has auto spell correction for the commands you write.
- You can customize the command prompt with some cool themes using fish.
- The syntax highlighting feature of fish colors different parts of a command based on their roles, which can improve the readability of commands. It also helps us to spot errors with their unique colors.
- Fish also provides scripting, tab completion, and command history functionality.