Write a shell script program to perform all Arithmetic Operations using Command line arguments
To create a shell script that performs arithmetic operations using command line arguments in both Windows and Linux environments, you'll need to handle different syntax and scripting approaches. Here’s how you can do it for each:
### Linux Shell Script
In Linux, you can use a bash script to perform arithmetic operations. Save the following script in a file named `arithmetic.sh`:
```bash
#!/bin/bash
# Check if exactly 3 arguments are provided
if [ $# -ne 3 ]; then
echo "Usage: $0 <number1> <operator> <number2>"
exit 1
fi
# Extract arguments
num1=$1
operator=$2
num2=$3
# Perform arithmetic operations
case $operator in
+)
result=$(echo "$num1 + $num2" | bc)
;;
-)
result=$(echo "$num1 - $num2" | bc)
;;
\*)
_____ ________ __________ _______ ___ ___ ____ ______ ___.
________ ___ ____ _____ _____ ______ _____ ___ ___ ______ ______.
_________ ________ _________ ___ ___ _______ __________.
_________ _______ _________ _________ _____ _______ _________ _____ _________ ____ ______ _______.
_________ _________ _____ _____ _______ ___ ______ ______ ____ ______ _________.
_________ _________ _____ ________ ________ __________.
__________ _______ ___ _____ _____ _________ ____ __________ _____ __________ _______.
__________ _____ ________ __________ ______ ______ _______ _____ ____ _____ __________ _______.
________ _____ _____ ____ ________ ________ ____ ___.
__________ _____ ___ _____ ________ __________.
___ ____ _________ _____ _________ ___.
___ _______ __________ ________ _______ _________ ____ ___.
______ _____ __________ ______ ________ ______ _______ ____ ____ ___ _______ ______.
__________ _________ ___ __________ _______ __________ ______ _____ __________ ________ _________ __________.
____ ______ ________ ____ ___.
____ ____ ________ _________ ______.
_____ ____ _________ ___ ____ ____ _______ _____ ______.
_________ ___ ___ _____ __________ ______ ________ _____ _________ _____ ________.
_______ ______ _________ _________ _________ ___ __________ __________.
__________ _____ ________ ___ _________ _____ ______ ___ _______ ____ __________.
__________ _______ _____ __________ _______ _____ ___ ___ ______ __________.
___ ____ _____ __________ _______.
_______ _____ ________ __________ _______ __________ _____.
________ __________ _____ ______ ________ ______ _____ ___ ________ ______ ________.
___ ________ __________ _____ ___.
_____ ___ ____ _______ ____ ________ _______ ___ __________ ____ __________.
___ ____ __________ ___ _____ ___ ___ _________.
___ _____ _______ __________ ______ _______ _____.
_________ ____ __________ ___ ______ ___ ___ __________.
_______ ____ __________ ______ _______ ______ _________ ___ ______ _____ _________ _____.
_______ _________ ____ ________ ____ ______ ______ ___ __________.
________ _____ _____ _____ _______.
_____ ________ _________ _______ _____ _________ ______.
_______ _________ _______ ___ _____ _________.
______ ________ ________ ______ _________ _________ __________ __________ _____ ___ ________.
_________ ______ _______ ________ ____ ___ _______ ____ _________ __________.
_____ ________ ____ ________ _______.
_____ _________ ___ ______.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required