I have the following test.cpp c++ program
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
float a,b,c;
cout<<"Give 1st number";
cin>>a;
cout<<"Give 2nd number:";
cin>>b;
c=a+b;
cout<<"\n"<<a<<"+"<<b<<"="<<c<<endl;
return 0;
}
and I want to create a shell script which gives the input variables. I know how to pass one variable, and I would like to know if there is a way to pass 2 variables... like the following test.sh file which is not working
#!/bin/bash
g++ test.cpp -o testexe
chmod +x testexe
a=1
b=2
./testexe <<< $a $b
echo $a $b | ./testexe?./testexe <<<$'$a\n$b\n'or similar should work too$''needed to get a literal newline in there (for single line demonstration) but could be done over multiple lines otherwise.$'$a\n$b\n'won't expand the variables.<<"$a"$'\n'"$b"would be necessary for single-line usage (assuming the input needs to be newline split).