I have a program in C, which exits with code 1:
#include <stdlib.h>
...
datatype pop(stack* st){
if (empty(st)) exit(1);
return st->data[st->sp--];
}
...
int main(void){
...
// a is empty at this time
pop(a);
...
return 0;
}
And I have a bash script:
run() {
gcc -Wall -W -Wshadow -g -c "$filename.c"
echo "Exit code $?"
gcc -Wall -W -Wshadow -g "$filename.o" -o "$filename" -lm
./"$filename"
}
When I run a program, I get Exit code 0
, shouldn't I get Exit code 1
?
-pass-exit-codes
flag. So your when yourecho "Exit code $?"
displays0
, it means everything went OK ;)run() {...}
orfunction run {...}
(orfunction run() {...}
).run() {...}
, will edit.$?
is the exit for of the previous command. The exit code you're seeing is fromgcc
, not your program. Move the echo.