Using Command-line Arguments in Bash Scripts
📖 Scenario: You want to create a simple bash script that takes two numbers as input when you run it from the command line. Then, the script will add these two numbers and show the result.This is like when you use a calculator app and enter two numbers to get their sum, but here you will type the numbers next to the script name in the terminal.
🎯 Goal: Build a bash script that reads two numbers from the command line arguments $1 and $2, adds them, and prints the sum.
📋 What You'll Learn
Create a bash script that uses command-line arguments
Use
$1 and $2 to get the first and second input numbersAdd the two numbers inside the script
Print the result to the terminal
💡 Why This Matters
🌍 Real World
Many command-line tools accept inputs as arguments. Learning to use <code>$1</code>, <code>$2</code>, etc., helps automate tasks and create flexible scripts.
💼 Career
Understanding command-line arguments is essential for system administrators, DevOps engineers, and anyone writing shell scripts to automate workflows.
Progress0 / 4 steps