This code looks pretty elegant: (from here ) The same solution @Jay pointed out.
bash$ cat testing.c #include <stdio.h> char* say_hello() { return "hello world"; } float calc_xyzzy() { return 6.234; } int main(int argc, char** argv) { if (argc>1) { if (argv[1][0] =='1') { fprintf(stdout,"%s\n",say_hello()); } else if ( argv[1][0] == '2') { fprintf(stdout,"%g\n",calc_xyzzy()); } } return 0; } bash$ gcc -o testing testing.c bash$ ./testing 1 hello world bash$ ./testing 2 6.234 bash$ var_1="$(./testing 1)" bash$ var_2="$(./testing 2)" bash$ echo $var_1 hello world bash$ echo $var_2 6.234 bash$
H_7
source share