Linux Shell Scripting

Linux Shell Scripting Tutorial – Module 1: Introduction to Linux & Shell

Module 1: Introduction to Linux & Shell

In this module, we introduce the Linux operating system, the concept of a shell,
and how to write and execute your first shell scripts.
Understanding these basics is crucial before moving on to scripting automation.

✅ What is Linux?

  • Linux is a free and open-source operating system based on Unix.
  • It powers servers, desktops, embedded devices, and is widely used in DevOps and cloud environments.
  • The shell acts as an interface between the user and the operating system.

✅ What is a Shell?

  • A shell is a command-line interpreter that takes user commands and executes them.
  • Popular shells include sh, bash, zsh, fish.
  • Bash (Bourne Again SHell) is the most commonly used shell in Linux distributions.

✅ Interactive vs Non-Interactive Shell

  • Interactive shell: When you type commands directly into a terminal.
  • Non-interactive shell: When commands are run from a script file.

✅ Writing Your First Script

Every shell script starts with a shebang line that tells the system which interpreter to use.


#!/bin/bash
# My first shell script
echo "Hello, World!"
  

✅ Making a Script Executable

  • Save the script as hello.sh
  • Give execute permission:

chmod +x hello.sh
./hello.sh
  

Output:


Hello, World!
  

✅ Understanding PATH

  • $PATH is an environment variable that lists directories searched for executables.
  • If your script is not in $PATH, you must run it with ./script.sh.
  • You can add your script directory to PATH temporarily:

export PATH=$PATH:/home/user/scripts
  

✅ Summary

  • Linux shell provides a powerful command-line interface for automation.
  • Bash is the most widely used shell interpreter.
  • Scripts begin with #!/bin/bash and can be made executable with chmod +x.
  • PATH environment variable decides where the system looks for executables.

✅ By the end of this module, you should be able to create a simple shell script,
make it executable, and run it on your Linux system.

Leave a Reply

Your email address will not be published. Required fields are marked *