0
0
Bash Scriptingscripting~15 mins

Arithmetic expansion $(( )) in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Arithmetic Expansion $(( )) in Bash
📖 Scenario: You are managing a small store's daily sales. You want to calculate the total number of items sold by adding the sales from morning and afternoon shifts.
🎯 Goal: Build a simple Bash script that uses arithmetic expansion $(( )) to add two numbers representing sales and display the total.
📋 What You'll Learn
Create two variables morning_sales and afternoon_sales with exact values
Create a variable total_sales that uses arithmetic expansion $(( )) to add the two sales variables
Print the total sales using echo
💡 Why This Matters
🌍 Real World
Calculating totals, counts, or simple math in shell scripts is common for automating tasks like sales reports or inventory checks.
💼 Career
Knowing arithmetic expansion helps you write scripts that handle numbers easily, a useful skill for system administrators and automation engineers.
Progress0 / 4 steps
1
Set up sales variables
Create two variables called morning_sales and afternoon_sales with values 120 and 80 respectively.
Bash Scripting
Need a hint?

Use variable=value format without spaces around =.

2
Calculate total sales
Create a variable called total_sales that uses arithmetic expansion $(( )) to add morning_sales and afternoon_sales.
Bash Scripting
Need a hint?

Use total_sales=$((morning_sales + afternoon_sales)) to add the two variables.

3
Display the total sales
Use echo to print the value of total_sales.
Bash Scripting
Need a hint?

Use echo $total_sales to show the result.

4
Run the script and see the result
Run the script to display the total sales number. The output should be 200.
Bash Scripting
Need a hint?

Run the script in your terminal using bash script.sh or ./script.sh if executable.