Skip to content

Instantly share code, notes, and snippets.

@sulincix
Created August 3, 2022 15:34
Show Gist options
  • Save sulincix/e96b520a44736c3f42cea06ce6dd51d9 to your computer and use it in GitHub Desktop.
Save sulincix/e96b520a44736c3f42cea06ce6dd51d9 to your computer and use it in GitHub Desktop.
Sh compiler
#!/bin/bash
if [[ $# -ne 2 ]] ; then
echo "Usage shc (source.sh) (output.c)"
exit 2
fi
echo "#include <stdlib.h>" > "$2"
echo "int main(){" >> "$2"
echo " return system(\" \\" >> "$2"
cat $1 | sed 's/\\/\\\\/g;s/"/\\"/g;s/$/\\/g' >> "$2"
echo " \");" >> "$2"
echo "}" >> "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment