mirror of https://github.com/01-edu/public.git
eslopfer
2 years ago
2 changed files with 34 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
|
||||||
|
# Check if two arguments were provided |
||||||
|
if [ $# -ne 2 ] |
||||||
|
then |
||||||
|
echo "Error: two numbers must be provided" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
# Check if the arguments are numeric |
||||||
|
if ! [[ $1 =~ ^-?[0-9]*\.?[0-9]+$ ]] || ! [[ $2 =~ ^-?[0-9]*\.?[0-9]+$ ]] |
||||||
|
then |
||||||
|
echo "Error: both arguments must be numeric" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
# Check if the second argument is not 0 |
||||||
|
if [ $(echo "$2 == 0" | bc) -eq 1 ] |
||||||
|
then |
||||||
|
echo "Error: division by zero is not allowed" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
# Divide the first argument by the second using bc |
||||||
|
result=$(echo "$1 / $2" | bc ) |
||||||
|
|
||||||
|
# Output the result |
||||||
|
echo $result |
Loading…
Reference in new issue