Skip to content

Instantly share code, notes, and snippets.

@onyxcode
Last active February 17, 2021 21:30
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 onyxcode/9a9960e4aa4c7c3940b473f724103b5d to your computer and use it in GitHub Desktop.
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.
#!/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
@onyxcode
Copy link
Author

You can now keep the compiled binary by adding "-k keep" to the end of your command

@datkat21
Copy link

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