Created
May 1, 2014 20:25
-
-
Save kevinwright/39d75a2151c17df8013f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#disable globbing of the * | |
set -f | |
INPUT=$1 | |
SUBBED=($( | |
sed \ | |
-e "s,multiply,*,g" \ | |
-e "s,divide,/,g" \ | |
-e "s,add,+,g" \ | |
-e "s,subtract,-,g" \ | |
-e "s,apply,,g" \ | |
-e "s, *,,g" \ | |
$INPUT | |
)) | |
EXPR="" | |
for (( idx=${#SUBBED[@]}-1 ; idx>=0 ; idx-- )) ; do | |
LINE="${SUBBED[idx]}" | |
EXPR="($EXPR $LINE)" | |
done | |
echo $EXPR | |
echo $(($EXPR)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment