I'm trying to write a system that grades a c++ code with pre-written examples that i have ready. It's a very simple c++ code like the following:
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
if (a > 100)
cout << "Big";
else
cout << "Small";
return 0;
}
So i want to test and grade this program with a bash, declare a score variable and echo it in the end. Here's what i wrote(I've marked where i need help writing with double quotes)
#!/bin/bash
g++ new.cpp -o new
test1=101
test2=78
score=0
if [ "Result of executing ./new with $test1 variable as input"=="Big" ]
then
(( score += 50 ))
fi
if [ "Result of executing ./new with $test2 variable as input"=="Small" ]
then
(( score += 50 ))
fi
echo $score
Also i'm still very new to bash so if you can tell me a simpler way to use bash for the examples (like loops) i'd love to hear it. Thanks!
bashscript can read.if [ "Result of executing ./new with $test1 variable as input"=="Big" ]is always true, sinceResult of executing ./new with $test 1 variable as input==Bigis a non-empty string.[is a fickle beast.