Last active
July 19, 2018 01:59
-
-
Save 5a494d/683c306aacdde7186b319c55482c9bb5 to your computer and use it in GitHub Desktop.
Execute c/c++ single file with bash
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 | |
echo "# File name: $1" | |
CPPFILE=$1 | |
# Remember to put file path to environment system | |
# .profile .bash_profile .bash_login | |
# if [ -d "$HOME/.bash" ] ; then | |
# PATH="$PATH:$HOME/.bash" | |
# fi | |
if [ -f "./$CPPFILE" ]; then | |
file=$(basename -- "$CPPFILE") | |
CPPEXT="${CPPFILE##*.}" | |
CPPNAME="${CPPFILE%.*}" | |
echo "# Compiling" | |
COMFILE="$CPPNAME.o" | |
g++ -c ./$CPPFILE -o ./$COMFILE | |
g++ -o $CPPNAME $COMFILE | |
if [ -f "./$CPPNAME" ]; then | |
echo "# Executing file" | |
chmod +x ./$CPPNAME | |
echo "######################### BEGIN OUTPUT ##########################" | |
./$CPPNAME | |
echo "######################### END OUTPUT ############################" | |
else | |
echo "################## HOUSTON WE HAVE A PROBLEM ####################" | |
fi | |
else | |
echo "# File not found!" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment