#!/bin/bash
function back()
{
sleep $1
exit $2
}
back $1 $2 &
b=$!
if `wait $!`;then
echo success
else
echo failure
fi
bash-3.00# ./back 300 0
failure
bash-3.00# ./back 300 1
failure
I was expecting success as exit status when I send 0, but I am still getting failure.
Also, wait doesn't wait for 300 seconds. Instead, I get the message immediately. I assume $! is the immediate child of $$ in my script. Isn't it?
Is it possible to capture the exit status of wait like exit_status=$(wait $!)?
if ! ((exit_status));then
echo sucess
else
failure
fi