0

I want to define a variable in a shell script that I pass to a c++ executable. At the moment my shell script looks like,

#!/bin/sh
aTest="hello"
echo $aTest
./hello $aTest

which I use to run an executable for a c++ program,

#include <iostream>
using namespace std;

int main()
{
  string aString;
  cin>>aString;
  cout << aString << endl;
}

However when I run the shell script from bash it just hangs, until I give it a parameter on bash.

Any ideas how can I get this to work as I would like?

ben18785
  • 356
  • 1
  • 5
  • 15
  • Does this help! http://stackoverflow.com/questions/19025763/linux-script-running-c-program – Ehsan Dec 03 '16 at 03:49
  • 1
    This isn't the exact same at the question being linked (although it is a duplicate of some question) -- that is one approach. Depending on the use case, OP could also want to send the string to stdin, in which case a pipe should be used in the bash script: `echo $aTest | ./hello` instead of `./hello $aTest`. Either one is a possible way depending on the use case. – Daniel Underwood Dec 03 '16 at 03:52

0 Answers0