Add calc.sh
This commit is contained in:
parent
d41e2b1e67
commit
cc335ca6a5
|
@ -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))"
|
Loading…
Reference in New Issue