Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Created May 1, 2014 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinwright/547e2012a152deb64de1 to your computer and use it in GitHub Desktop.
Save kevinwright/547e2012a152deb64de1 to your computer and use it in GitHub Desktop.
minified evaluator
#!/bin/bash
set -f
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" $1))
EXPR=""
for (( idx=${#SUBBED[@]}-1 ; idx>=0 ; idx-- )) ; do EXPR="($EXPR ${SUBBED[idx]})"; done
echo $(($EXPR))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment