I'm writing a script that runs a process in the background while shows a progress bar until the mentioned process ends. my question is, how can I check the exit code of that process??
thanks in advance
I'm writing a script that runs a process in the background while shows a progress bar until the mentioned process ends. my question is, how can I check the exit code of that process??
thanks in advance
The wait
builtin will return the exit code of the waited process if you specify a PID or job spec. (Note that it returns zero if you don't specify either of those.)
Here's how you could use it:
#! /bin/bash
(exit 10)&
pid=$!
wait $pid
echo $?
This will print 10
.
You can use the $? variable:
command & #run command in background
pid=$! #get pid
wait $! #wait for the sucker to finish
status=$? #exitcode for pid