-
-
Save bokwoon95/80a2aafe236317a636864b576d5f333b to your computer and use it in GitHub Desktop.
Run C files by compiling, executing and deleting the binary. Emulating a C interpreter
This file contains hidden or 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 | |
in="$1" | |
out="$(echo "$in" | sed 's/\.c$//g')" | |
rand="$(date +%s)$(LC_ALL=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c10)" | |
cleanup() { | |
rm -rf "$rand$out" | |
} | |
trap cleanup EXIT | |
if ! clang -Wall -Wextra "$in" -o "$rand$out"; then | |
exit 1 | |
fi | |
if ! clang -Wall -Wextra -Werror "$in" -o "$rand$out" >/dev/null 2>&1; then | |
read -p 'Warnings detected, proceed? (enter to proceed, n to abort) ' proceed | |
if [ "$proceed" = 'n' ]; then | |
echo 'aborted' | |
exit 1 | |
fi | |
fi | |
./"$rand$out" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment