Variables in Shell Scripting
Example 1: Defining Variables in a Bash Script
Example 2: Read, Store and Display User Input using Bash Script
Example 3: Read User Input with Prompt Message using Bash Script
Example 4: Concatenating Multiple Variables
Example 5: Passing Values to Variables as Command Line Arguments
Example 6: Print Environment Variable using Bash Script
Operators in Shell Scripting
Example 1: Adding Two Numbers using Bash Script
Example 2: Subtracting Two Numbers using Bash Script
Example 3: Division of Two Numbers using Bash Script
Example 4: Calculating the Remainder of a Division using Bash Script
Example 5: Generating a Random Number between 1 and 50 Using Bash Script
Example 6: Generating a Random Number between Two Given Numbers
Example 7: Performing Multiple Mathematical Operations in a Script
Example 8: Performs a Bitwise Operation Based on User Input
Conditionals in Shell Scripting
Example 1: Check if a Number is an Even or Odd
Example 2: Perform an Arithmetic Operation Based on User Input
Example 3: Performs a Logical Operation Based on User Input
Example 4: Check if a Given Input is a Valid Email ID
Example 5: Check if a Given Input is a Valid URL
Example 6: Check if a Given Number is Positive or Negative
Example 7: Check if a File is Writable
Example 8: Check if a File Exists or Not
Example 9: Check if a Directory Exists or Not
Strings in Shell Scripting
Example 1: Find the Length of a String
Example 2: Check if Two Strings are Equal
Example 3: Convert All Uppercase Letters in a String to Lowercase
Example 4: Remove All Whitespace from a String
Example 5: Reverse a String
Example 6: Reverse a Sentence
Example 7: Capitalize the First Letter of a Word
Example 8: Replace a Word in a Sentence
Loops in Shell Scripting
Example 1: Print Numbers from 5 to 124
Example 2: Print Even Numbers from 1 to 10
Example 3: Print the Multiplication Table of a Number
Example 4: Calculate the Sum of Digits of a Given Number
Example 5: Calculate the Factorial of a Number
Example 6: Calculate the Sum of the First “n” Numbers
Arrays in Shell Scripting
Example 1: Loop through Array Elements
Example 2: Find the Smallest and Largest Elements in an Array
Example 3: Sort an Array of Integers in Ascending Order
Example 4: Remove an Element from an Array
Example 5: Inserting an Element into an Array
Example 6: Slicing an Array using Bash Script
Example 7: Calculate the Average of an Array of Numbers
Example 8: Find the Length of an Array
Functions in Shell Scripting
Example 1: Check if a String is a Palindrome
Example 2: Check if a Number is Prime
Example 3: Convert Fahrenheit to Celsius
Example 4: Calculate the Area of a Rectangle
Example 5: Calculate the Area of a Circle
Example 6: Grading System
Task-Specific Bash Scripts (44 Examples)
Regular Expression Based Scripts
1. Search for a Pattern inside a File
2. Replace a Pattern in a File
File Operations with Shell Scripts
3. Take Multiple Filenames and Prints their Contents
4. Copy a File to a New Location
5. Create a New File and Write Text Inside
6. Compare the Contents of Two Given Files
7. Delete a Given File If It Exists
8. Renames a File from Script
File Permission Based Shell Scripts
9. Check the Permissions of a file
10. Sets the Permissions of a Directory for the Owner
11. Change the File Owner
12. Change the Overall Permissions of a File
Network Connection Based Shell Scripts
13. Check a Remote Host for its Availability
14. Test if a Remote Port is Open
15. Checking Network Connectivity
16. Automating Network Configuration
17. Process Management: Check if a Process is running
Process Management Based Shell Scripts
18. Start a Process if It's Not Already Running
19. Stop a Running Process
20. Restart a Running process
21. Monitor a Process and Restart It If Crashes
22. Display the Top 10 CPU-Consuming Processes
23. Display the Top 10 Memory-Consuming Processes
24. Kill Processes of a Specific User
25. Kill All Processes that are Consuming More Than a Certain Amount of CPU
26. Kill All Processes that are Consuming More Than a Certain Amount of
Memory.
System Information Based Shell Scripts
27. Check the Number of Logged-in Users
28. Check the Operating System Information
29. Check the System’s Memory Usage
30. Check the System’s Disk Usage
31. Check the System’s Network Information
32. Check the Uptime
33. Check the System Load Average
34. Check the System Architecture
35. Count the Number of Files in the System
Advanced Tasks with Shell Scripts
36. Automated Backup
37. Generate Alert if Disk Space Usage Goes Over a Threshold
38. Create a New User and Add to Sudo Group
39. Monitor Network traffic
40. Monitor CPU and Memory Usage
41. Creating a Script and Adding It to PATH
42. Running a Command at Regular Intervals
43. Downloading Files from a List of URLs
44. Organizes Files in a Directory Based on Their File Types