2
0
Fork 0
mirror of https://github.com/alexanderepstein/Bash-Snippets synced 2018-11-08 02:59:35 +01:00

Validate expression in newton

This commit is contained in:
Alex Epstein 2017-07-27 19:43:28 -04:00
parent 4541c13c28
commit be516b6772

View file

@ -77,6 +77,13 @@ getConfiguredClient()
fi
}
validateExpression()
{
local parsedExpression
parsedExpression=$(echo $1 | grep -Eo "[0-9 + -- / * . a-Z ~ :]*")
if [[ $parsedExpression != $1 ]];then { echo "Error: Expression contains invalid characters";return 1;}; fi
}
encodeEquation()
{
originalEquation=$1
@ -174,6 +181,7 @@ elif [ $# -gt 2 ];then echo "Error: newton only accepts two arguments, operation
validateOperation $1 || exit 1
validateExpression $2 || exit 1
encodeEquation $2 || exit 1
if [[ $opType == "simple" ]];then getSimpleResponse || exit 1;fi
printAnswer