Types of Shells in Linux shell scripting?
There are different types of shells available in Linux. Let's explore the different types of shells with examples.
1. Bash (Bourne Again Shell)
Description: Bash is the most widely used shell in Linux distributions. It offers command completion, history, and scripting capabilities. Here we have used "bash" in shebang line to use Bash shell. You need to save this file with ".bash" extension.
Example:-
#!/bin/bash echo "This script is running in Bourne Again Shell" date
2. Sh (Bourne Shell)
Description: The original Unix shell developed by Stephen Bourne. It's simple and lightweight. Here we have used "sh" in shebang line to use Bourne Shell . You need to save this code with ".sh" extension.
Example:
#!/bin/sh echo "This script is running in Bourne Shell" date
3. Zsh (Z Shell)
Description: Zsh is an extended version of the Bourne Shell with many improvements. It supports themes, plugins, and powerful scripting. Here we have used "zsh" in shebang line to use Z shell. You need to save this file with ".zsh" extension.
Example:
#!/bin/zsh echo "This script is running in Z shell" date
4. Csh (C Shell)
Description: Developed by Bill Joy, C Shell has a syntax resembling the C programming language. It supports job control and history substitution. Here we have used "csh" in the Shbang line to use C Shell. You need to save this code with ".csh" extension.
Example:
#!/bin/csh echo "This script is running in C Shell" date
5. Tcsh (TENEX C Shell)
Description: Tcsh is an enhanced version of the C Shell. It offers command-line editing and command history. Here we have used "tcsh" to use Tenex C Shell in Shebang line. You need to save this code with ".tcsh " extension.
Example:
#!/bin/tcsh echo "This script is running in TENEX C Shell" date
6. Ksh (Korn Shell)
Description: Developed by David Korn, Korn Shell combines features of the Bourne and C Shells. It offers advanced scripting capabilities and associative arrays. Here we have used "ksh" to use Korn Shell in Shebang line. You need to save this code with ".ksh" extension.
Example:
#!/bin/ksh echo "This script is running in Korn Shell" date
Each of these shells has unique features and capabilities, allowing users to choose the one that best fits their needs and preferences. Shell scripting in Linux is a powerful tool for automating tasks, managing system operations, and performing complex processes.