shell script collection
1 .Write a Simple shell script for basic arithmetic and logical calculations. ✅ Shell Script: calc.sh #!/bin/bash # Basic Arithmetic and Logical Calculations echo "Enter first number:" read a echo "Enter second number:" read b # Arithmetic Operations sum=$((a + b)) diff=$((a - b)) prod=$((a * b)) div=$((a / b)) mod=$((a % b)) echo "Arithmetic Calculations:" echo "$a + $b = $sum" echo "$a - $b = $diff" echo "$a * $b = $prod" echo "$a / $b = $div" echo "$a % $b = $mod" # Logical Comparisons echo "Logical Comparisons:" if [ $a -eq $b ]; then echo "$a is equal to $b" else echo "$a is not equal to $b" fi if [ $a -gt $b ]; then echo "$a is greater than $b" else echo "$a is not greater than $b" fi if [ $a -lt $b ]; then echo "$a is less than $b" else echo "$a is not less than $b" fi π» How to Run It 1. Save the script to a file named calc.sh. M...
Comments
Post a Comment