Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Created May 1, 2014 20:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinwright/39d75a2151c17df8013f to your computer and use it in GitHub Desktop.
Save kevinwright/39d75a2151c17df8013f to your computer and use it in GitHub Desktop.
#!/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