Skip to content

Instantly share code, notes, and snippets.

@baerla
Created February 3, 2021 13:25
Show Gist options
  • Save baerla/edf9b1ed4f0f9a4cdfd9b4d91e7c80c4 to your computer and use it in GitHub Desktop.
Save baerla/edf9b1ed4f0f9a4cdfd9b4d91e7c80c4 to your computer and use it in GitHub Desktop.
Skript to run .cpp and .h C++ files
#!/bin/bash
# syntax: ./test.sh <file.h> <arguments>
createdNewFile=false
file=${1##*/}
echo $file
filename=${file%.h}
echo $filename
path=${1%$file}
if [[ $file != $filename ]]; then
newPath="$path$filename.cpp"
echo "Path: $newPath"
cat $1 > $newPath
createdNewFile=true
else #.cpp
newPath="$path$file"
fi
g++ -Wall -std=c++11 ${*:2} $newPath
echo -e "\n\n"
./a.out #${*:2}
rm ./a.out
if [[ $createdNewFile == true ]]; then
rm $newPath
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment