Im trying to use one of the inputs from my bash script into my c program and i just dont know how to do so. What command should i add for the argument to be passed on to my c program? Thanx My script is - bash script
Asked
Active
Viewed 126 times
-3
-
5Don't post pictures of code. Post your code as properly formatted text into the question. Before doing so read this: [ask] – Jabberwocky Apr 16 '21 at 08:11
-
2Hint: `argc` and `argv` in `main()`. That's *exactly* what they're for. `prog.exe blah blah`. – tadman Apr 16 '21 at 08:12
-
Checkout : https://stackoverflow.com/questions/3024197/what-does-int-argc-char-argv-mean – Louis Caron Apr 16 '21 at 08:15
-
A very complete answer about this problem can be found here: https://stackoverflow.com/questions/3024197/what-does-int-argc-char-argv-mean – Louis Caron Apr 16 '21 at 08:17
-
yeah i know how to do that within my c prog i just dk what to write in my script: gcc -c -g -Wall calc_statistics.c gcc -o prog.exe calc_statistics.c "$1" – shani zehavi Apr 17 '21 at 17:44
1 Answers
0
I guess that you want to pass the argument to prog.exe
and not to gcc
, then
gcc -c -g -Wall calc_statistics.c gcc -o prog.exe && ./prog.exe "$1"
That is, compile the program and if there are no error run it with the argument.
It's not very efficient to compile the program every time the script runs so you can move gcc
out.
You can also check your script using shellcheck.

Diego Torres Milano
- 65,697
- 9
- 111
- 134