-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommitcompile.sh
executable file
·36 lines (34 loc) · 1.03 KB
/
commitcompile.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
#!/bin/bash
# a shell script which copiles a file with gcc and if no errors exist, it commits it to git with the output gotten from running the code
# define usage function
usage(){
echo "Usage: $0 filename"
exit 1
}
# define is_file_exits function
# $f -> store argument passed to the script
is_file_exits(){
local f="$1"
[[ -f "$f" ]] && return 0 || return 1
}
# invoke usage
# call usage() function if filename not supplied
[[ $# -eq 0 ]] && usage
# Invoke is_file_exits
if ( is_file_exits "$1" ) # if the file (argument 1) didn't exist
then
a=$(gcc jagaja.c 2>&1) # 2>&1 catches both, STDOUT and STDERR
if [ -z "$a" ] # check if the variable is set, returns true for an empty string too
then
b=$(./a.out 1) # runs the compiled code
c=$(git commit -a -m "$b
$2" 2>&1) # commits with output message followed by argument 2 from the command line
echo " --- GIT TEATAB --- "
echo $c # git output
else
echo " --- KOMPILEERUMINE EBAÕNNESTUS ---"
echo $a #if the compilaton failed, it outputs all
fi
else
echo "File not found"
fi