-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkcpp.sh
executable file
·44 lines (39 loc) · 943 Bytes
/
mkcpp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /bin/bash
# Created by Barrett Lewis
# creates a cpp file
FILE="${1}.cpp"
FILEL="`pwd`/${FILE}" #location of file
CMD="${2}"
function createCPP() #function to create the file template
{
echo "#include <iostream>" > $FILE
echo >> $FILE
echo "using namespace std;" >> $FILE
echo >> $FILE
if [ x$CMD == "x-cmd" ]
then
echo "int main(int argc, char *argv[])" >> $FILE
else
echo "int main()" >> $FILE
fi
echo "{" >> $FILE
echo >> $FILE
echo " return 0;" >> $FILE
echo "}" >> $FILE
vim $FILE
}
if [ ! -f $FILEL ] #checks if file doesn't exist
then
createCPP
else
echo "<${FILE}> already exists in location <`pwd`/${FILE}>"
echo "Do you wish to overwrite <${FILE}>, this process can't be reversed"
while true; do #gets user input to confirm or deny rewriting file
read -p " yes or no " yn
case $yn in
[Yy]* ) createCPP; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi