Last active
February 17, 2021 21:30
-
-
Save onyxcode/9a9960e4aa4c7c3940b473f724103b5d to your computer and use it in GitHub Desktop.
Simple script to complie C files, run them, and them immediately delete them after.
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 | |
: ' | |
░█████╗░ ░█████╗░░█████╗░███╗░░░███╗██████╗░██╗██╗░░░░░███████╗██████╗░ | |
██╔══██╗ ██╔══██╗██╔══██╗████╗░████║██╔══██╗██║██║░░░░░██╔════╝██╔══██╗ | |
██║░░╚═╝ ██║░░╚═╝██║░░██║██╔████╔██║██████╔╝██║██║░░░░░█████╗░░██████╔╝ | |
██║░░██╗ ██║░░██╗██║░░██║██║╚██╔╝██║██╔═══╝░██║██║░░░░░██╔══╝░░██╔══██╗ | |
╚█████╔╝ ╚█████╔╝╚█████╔╝██║░╚═╝░██║██║░░░░░██║███████╗███████╗██║░░██║ | |
░╚════╝░ ░╚════╝░░╚════╝░╚═╝░░░░░╚═╝╚═╝░░░░░╚═╝╚══════╝╚══════╝╚═╝░░╚═╝ | |
(Works on any Linux distro with gcc and chmod) | |
' | |
while getopts f:k: flag | |
do | |
case "${flag}" in | |
f) file=${OPTARG};; | |
k) keep=${OPTARG};; | |
esac | |
done | |
if [[ -z "$file" ]]; then | |
echo "Must provide filename with -f" 1>&2 | |
exit 1 | |
fi | |
gcc ${file} -Wall -Wextra -pedantic -o ${file}.tmp | |
{ | |
chmod +x ${file}.tmp | |
} &> /dev/null | |
./${file}.tmp | |
if [[ "$keep" == "keep" ]]; then | |
true | |
fi | |
if [[ -z "$keep" ]]; then | |
{ | |
rm ${file}.tmp | |
} &> /dev/null | |
fi |
ok i might actually use this but my c skills are kinda :cough:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can now keep the compiled binary by adding "-k keep" to the end of your command