SlideShare a Scribd company logo
6
Most read
Introduction to Shell
Scripting
Shell Scripts
Executable file comprising a series of shell commands executed in sequence.
Within the file, you can include:
● Shell declaration (#!/bin/bash)
● Commentary lines (# comments)
● Various commands (echo, cp, grep, etc.)
● Control statements (if, while, for, etc.)
● Ensure executable permissions (e.g., -rwx r-x r-x)
● Call script using absolute path (e.g.,-/home/userdir/script.bash)
● Calling from the current directory, use ./script.bash
Getting Started with Shell Scripts
● touch hello.sh - creates an empty text file
● Shebang line (#!/bin/bash) specifies bash as the interpreter for
executing our script commands.
● Shell script structure-combines shebang (#!/bin/bash) and echo
commands to perform tasks, executed using ./scriptname.sh
● chmod +x hello.sh - makes script executable, allowing it to run as a
program
Working with Variables and User Input
● Script that collects user input using read variable and displays a
personalized greeting message
● Uses basic commands (read, echo) and variables
● chmod +x user_input.sh -Adds execute permissions to transform the script
into a directly runnable program file.
● ./user_input.sh -Executes the script from the current directory
Conditional Statements
● Uses if-else statements to check if a user's number is greater than 10
● Uses basic conditional operators (-gt) and keywords (if, then, else, fi) to make
decisions based on input
● If-Then: Conditional execution of code.
Syntax:
`if [ condition ]; then action; fi`
Introduction to Shell Scripting - RHCSA+.pdf
● chmod +x conditional.sh -Makes the script executable
● ./conditional.sh -Runs the script and verify that it evaluates user input
against the condition, and display appropriate message based on the
number comparison.

More Related Content

DOCX
What is a shell script
PPTX
Licão 05 scripts exemple
PDF
Shell Scripting Intermediate - RHCSA+.pdf
PPTX
Unix shell scripting basics
PPTX
Shell & Shell Script
PPTX
Shell & Shell Script
PDF
Shell scripting _how_to_automate_command_l_-_jason_cannon
DOCX
sguide to write shell script in linux.docx
What is a shell script
Licão 05 scripts exemple
Shell Scripting Intermediate - RHCSA+.pdf
Unix shell scripting basics
Shell & Shell Script
Shell & Shell Script
Shell scripting _how_to_automate_command_l_-_jason_cannon
sguide to write shell script in linux.docx

Similar to Introduction to Shell Scripting - RHCSA+.pdf (20)

PPT
Shell programming
PPT
2-introduction_to_shell_scripting
PPTX
BWU_BTA_22_508_cSd how os are implemented.pptx
PDF
Shell tutorial
PPT
Advanced linux chapter ix-shell script
PDF
3.1.d manual bash script guide lsstv 2.0r11
PPT
Unix shell scripting basics
PPT
Unix Shell Scripting Basics
PPTX
Shell Script Tutorial
PDF
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
PPT
Unix Shell Scripting Basics
PPTX
Linux Shell Scripting
PDF
Shell Programming_Module2_Part2.pptx.pdf
PDF
BASH Shell Script Training in Noida- Rexton It Solution
PDF
Introduction to Shell Scripting: All About It
PPT
Best training-in-mumbai-shell scripting
PPTX
Bash Shell Scripting
PPTX
Shell Programming Language in Operating System .pptx
PDF
Improve Command Line Productivity - RHCSA (RH134).pdf
Shell programming
2-introduction_to_shell_scripting
BWU_BTA_22_508_cSd how os are implemented.pptx
Shell tutorial
Advanced linux chapter ix-shell script
3.1.d manual bash script guide lsstv 2.0r11
Unix shell scripting basics
Unix Shell Scripting Basics
Shell Script Tutorial
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Unix Shell Scripting Basics
Linux Shell Scripting
Shell Programming_Module2_Part2.pptx.pdf
BASH Shell Script Training in Noida- Rexton It Solution
Introduction to Shell Scripting: All About It
Best training-in-mumbai-shell scripting
Bash Shell Scripting
Shell Programming Language in Operating System .pptx
Improve Command Line Productivity - RHCSA (RH134).pdf
Ad

More from RHCSA Guru (20)

PDF
Flatpak CLI Application Management & Building on RHEL.pdf
PDF
How to Set Up a RHEL 9 Virtual Lab for RHCSA Practice.pdf
PDF
CompTIA Linux (Plus) Exam Overview .pdf
PDF
Linux Professional Institute LPIC-1 Exam.pdf
PDF
LVM Management & Disaster Recovery - RHCSA+.pdf
PDF
Managing Multiple Logical Volumes - RHCSA+.pdf
PDF
Master Logical Volume Management - RHCSA+.pdf
PDF
Ansible Vault Encrypting and Protecting Secrets - RHCE.pdf
PDF
Ansible Variables in Playbook - RHCE.pdf
PDF
Comprehensive Guide to Ansible Application Roles.pdf
PDF
Using Tags in Ansible Playbooks RHCE.pdf
PDF
Comprehensive Guide to Ansible Roles - RHCE
PDF
Mastering Handlers, Conditions, and Loops in Ansible Playbooks - RHCE.pdf
PDF
Essential Ad-hoc Commands in Ansible - RHCE.pdf
PDF
RHEL in Shell Scripting Advanced - RHCSA+.pdf
PDF
Command Line Text Processing - RHCSA +.pdf
PDF
Mounting and Creating Links - RHCSA (RH124) .pdf
PDF
Basic Command Line Tools - RHCSA (RH124).pdf
PDF
Podman Networking Essentials - RHCSA+.pdf
PDF
Building and Running Podman Containers - RHCSA+.pdf
Flatpak CLI Application Management & Building on RHEL.pdf
How to Set Up a RHEL 9 Virtual Lab for RHCSA Practice.pdf
CompTIA Linux (Plus) Exam Overview .pdf
Linux Professional Institute LPIC-1 Exam.pdf
LVM Management & Disaster Recovery - RHCSA+.pdf
Managing Multiple Logical Volumes - RHCSA+.pdf
Master Logical Volume Management - RHCSA+.pdf
Ansible Vault Encrypting and Protecting Secrets - RHCE.pdf
Ansible Variables in Playbook - RHCE.pdf
Comprehensive Guide to Ansible Application Roles.pdf
Using Tags in Ansible Playbooks RHCE.pdf
Comprehensive Guide to Ansible Roles - RHCE
Mastering Handlers, Conditions, and Loops in Ansible Playbooks - RHCE.pdf
Essential Ad-hoc Commands in Ansible - RHCE.pdf
RHEL in Shell Scripting Advanced - RHCSA+.pdf
Command Line Text Processing - RHCSA +.pdf
Mounting and Creating Links - RHCSA (RH124) .pdf
Basic Command Line Tools - RHCSA (RH124).pdf
Podman Networking Essentials - RHCSA+.pdf
Building and Running Podman Containers - RHCSA+.pdf
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
Teaching material agriculture food technology
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
sap open course for s4hana steps from ECC to s4
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
A comparative analysis of optical character recognition models for extracting...
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Teaching material agriculture food technology
Assigned Numbers - 2025 - Bluetooth® Document
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Introduction to Shell Scripting - RHCSA+.pdf

  • 2. Shell Scripts Executable file comprising a series of shell commands executed in sequence. Within the file, you can include: ● Shell declaration (#!/bin/bash) ● Commentary lines (# comments) ● Various commands (echo, cp, grep, etc.) ● Control statements (if, while, for, etc.) ● Ensure executable permissions (e.g., -rwx r-x r-x) ● Call script using absolute path (e.g.,-/home/userdir/script.bash) ● Calling from the current directory, use ./script.bash
  • 3. Getting Started with Shell Scripts ● touch hello.sh - creates an empty text file ● Shebang line (#!/bin/bash) specifies bash as the interpreter for executing our script commands.
  • 4. ● Shell script structure-combines shebang (#!/bin/bash) and echo commands to perform tasks, executed using ./scriptname.sh ● chmod +x hello.sh - makes script executable, allowing it to run as a program
  • 5. Working with Variables and User Input ● Script that collects user input using read variable and displays a personalized greeting message ● Uses basic commands (read, echo) and variables
  • 6. ● chmod +x user_input.sh -Adds execute permissions to transform the script into a directly runnable program file. ● ./user_input.sh -Executes the script from the current directory
  • 7. Conditional Statements ● Uses if-else statements to check if a user's number is greater than 10 ● Uses basic conditional operators (-gt) and keywords (if, then, else, fi) to make decisions based on input ● If-Then: Conditional execution of code. Syntax: `if [ condition ]; then action; fi`
  • 9. ● chmod +x conditional.sh -Makes the script executable ● ./conditional.sh -Runs the script and verify that it evaluates user input against the condition, and display appropriate message based on the number comparison.