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:
parent
4541c13c28
commit
be516b6772
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue