Linux Classroom notes 04/Sep/2024

Shell Scripting

  • In the world of Linux, we use bash scripts majorly
  • In Linux when you execute commands, they are understood (parsed) by shells and necessary actions will be exectued.

Popular Linux Shells

Linux offers a variety of shells, each with unique features and capabilities. Some of the most popular and widely used shells include:

Bash (Bourne-Again SHell)

Bash is by far the most commonly used shell in Linux. It is the default shell in most Linux distributions and offers a wide range of features, including:

  • Command history
  • Tab completion
  • Scripting capabilities
  • Advanced customization options[1][2][3]

Zsh (Z Shell)

Zsh is a powerful and highly customizable shell that provides many features not available in Bash, such as:

  • Advanced completion capabilities
  • Spelling correction
  • Extensive customization options through themes and plugins
  • Compatibility with Bash scripts[1][3][4]

Fish (Friendly Interactive SHell)

Fish is a user-friendly shell designed to make working in the terminal more enjoyable. It includes features like:

  • Syntax highlighting
  • Auto-suggestions
  • Built-in help system
  • Customizable functions and commands[1][3]

Ksh (Korn Shell)

Ksh is a superset of the Bourne shell that combines elements of both the Bourne shell and C shell. It provides:

  • Powerful programming features
  • Interactive use enhancements
  • Compatibility with C shell scripts[2][4]

Tcsh (TENEX C Shell)

Tcsh is an improved version of the C shell that incorporates features like:

  • Command line editing
  • Completion
  • Syntax similar to the C programming language[2][4]

While Bash is the most widely used shell, other options like Zsh, Fish, Ksh, and Tcsh offer unique features and capabilities that may be better suited for certain use cases. The choice ultimately depends on individual preferences and requirements.

Citations:
[1] https://www.tutorialspoint.com/8-types-of-linux-shells
[2] https://www.geeksforgeeks.org/different-shells-in-linux/
[3] https://bigstep.com/blog/top-5-linux-shells-and-how-to-install-them
[4] https://www.hivelocity.net/kb/understanding-linux-shells/
[5] https://www.digitalocean.com/community/tutorials/different-types-of-shells-in-linux
[6] https://www.tecmint.com/different-types-of-linux-shells/
[7] https://phoenixnap.com/kb/linux-shells
[8] https://www.reddit.com/r/linux4noobs/comments/12wfzb8/best_shell_in_your_opinion_2023/

Lets write our first script in bash

  • Script
#!/bin/bash
echo "Hello"
  • Create a file called as hello.sh with above content and execute
    Preview
  • Try running this script with different values
#!/bin/bash
set -x
number=13
result=$((number%2))
echo $result

if [[ $result -eq 0 ]]; then
    echo "$number is even"
else
   echo "$number is odd"
fi

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Wordpress Development Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube