Add calc.sh

This commit is contained in:
raul 2024-12-11 09:50:07 +01:00
parent d41e2b1e67
commit cc335ca6a5
Signed by: raul
GPG Key ID: C1AA797073F17129
1 changed files with 35 additions and 0 deletions

35
calc.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
OPERADORES_DISPONIBLES=("+" "x" "-" "/")
VALID=false
FINAL_SEQUENCE=""
RE='^[0-9]+$'
NG='^-[0-9]+$'
for arg in $@; do
valid_num=false
valid_oper=false
for oper in "${OPERADORES_DISPONIBLES[@]}"; do
if [[ "$oper" == "$arg" ]] ; then
valid_oper=true
fi
done
if [[ $arg =~ $RE || $arg =~ $NG ]] ; then
valid_num=true
fi
if [[ "$valid_num" != true && "$valid_oper" != true ]] ; then
echo "INVALID CHARACTER DETECTED: $arg"
exit
fi
if [[ $arg == "x" ]]; then
FINAL_SEQUENCE+="* "
else
FINAL_SEQUENCE+="$arg "
fi
done
#echo "$FINAL_SEQUENCE"
echo "$FINAL_SEQUENCE = $(($FINAL_SEQUENCE))"