Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active December 13, 2015 21:29
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 PEZ/4977874 to your computer and use it in GitHub Desktop.
Save PEZ/4977874 to your computer and use it in GitHub Desktop.
A brainfuck bash frontend. Use like so: $ ./bf.sh '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.' Hello World! $
#!/bin/sh
CF="foo.c"
echo "#include <stdio.h>" > ${CF}
echo "int main() { char d[30000]; char *p=d;" >> ${CF}
echo $1 | while read -n1 c
do
case $c in
\>) echo "++p;" >> ${CF};;
\<) echo "--p;" >> ${CF};;
\+) echo "++*p;" >> ${CF};;
\-) echo "--*p;" >> ${CF};;
\.) echo "putchar(*p);" >> ${CF};;
\,) echo "*p=getchar();" >> ${CF};;
\[) echo "while (*p) {" >> ${CF};;
\]) echo "}" >> ${CF};;
esac
done
echo "}" >> ${CF}
cc ${CF}
./a.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment