Last active
August 4, 2021 02:38
-
-
Save AyushRawal/0a79af3da78190fdb59fa2c431bc70c2 to your computer and use it in GitHub Desktop.
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/sh | |
# A simple bash script to compile and execute cpp files during contests | |
usage="[USAGE]: runcpp [file] -- compile and execute file with input from input.txt | |
[OR]: runcpp clean -- delete input.txt and a.out if they exist | |
[OR]: runcpp -h | --help -- print this help mesaage and exit" | |
if [ ! $# -eq 1 ]; then | |
echo "Invalid usage! \n" | |
echo "$usage" | |
exit | |
fi | |
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
echo "$usage" | |
exit | |
fi | |
if [ "$1" = "clean" ]; then | |
if [ -e a.out ]; then | |
rm a.out | |
fi | |
if [ -e input.txt ]; then | |
rm input.txt | |
fi | |
else | |
if [ ! -e $1 ]; then | |
echo "[ERROR] $1 not found." | |
exit | |
fi | |
if [ ! -e input.txt ]; then | |
echo "[ERROR] input.txt not found." | |
exit | |
fi | |
g++ $1 | |
cat input.txt | ./a.out | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment