What's your question? You wrote code which returns a value and you wrote your test.sh script to do exactly what you want. The fact that your code appears incorrect is part of this.
The function returns an integer, however argv[i] is a character array. Therefore you could either change it so that main returns char *, or you return i. By the way, i becomes the value of 5 therefore returning argv[5] is nothing.
Code:
#include <stdio.h>
int main(int argc, const char *argv[]){
int i = 0;
for (; i < argc; ++i) {
printf("argv[%d] = '%s'\n", i, argv[i]);
}
return i;
}
Code:
~/testcode$ gcc -o test-return test-return.c
~/testcode$ ./test-return this is my function
argv[0] = './test-return'
argv[1] = 'this'
argv[2] = 'is'
argv[3] = 'my'
argv[4] = 'function'
~/testcode$ echo $?
5
I will grant that I do not know how to return a string from that function and have it be assigned to a bash variable.