0

I have a command that I am run with

COMMAND='some command'
eval $COMMAND &

and meanwhile display a spinner with

    # Get the pid of COMMAND                
    pid=$!                                  
                                            
    # If this script is killed, kill COMMAND
    trap "kill $pid 2> /dev/null" EXIT      
                                            
    # While COMMADN is running...           
    while kill -0 $pid 2> /dev/null; do     
        # Display the spinner               
        spin                                
    done                                    
                                            
    # Disable the trap on a normal exit.    
    trap - EXIT                             

I am grabbing the pid with pid=$!. How can I now check its return value? $? does not seem to give me the right return value, but rather the return value of eval.

I am looking for something like

RETVAL=retvalof($pid)

if [ $RETVAL -eq 0 ]; then
    echo "success"
else
    echo "error"
fi
neolith
  • 589
  • 8
  • 18

0 Answers0