Certainly! Here’s a simple shell script that prompts the user to enter two numbers and then calculates their sum:
#!/bin/bash
# Prompt the user to enter the first number
read -p "Enter the first number: " num1
# Prompt the user to enter the second number
read -p "Enter the second number: " num2
# Calculate the sum
sum=$((num1 + num2))
# Display the result
echo "Sum of $num1 and $num2 is: $sum"
Save this script to a file (e.g., calculate_sum.sh
), make it executable using chmod +x calculate_sum.sh
, and then run it:
./calculate_sum.sh
The script will prompt you to enter two numbers, and then it will calculate and display their sum.