How do I get the exit code from my subscript in main script - bash

Viewed 2109

How do I get the exit code from my subscript in main script. In my script below when the subscript fails it exits from the main script as well.

#!/bin/bash
function reportError() {
    if [ $1 -ne 0 ]; then
        echo $2
        exit $1
    fi
 }

 #executing the subscript

 /data/utility/testFolder.sh
 #calling the function if there is any error then function would update the 
 #audit table
 reportError $? "job is failed, please check the log for details"

Subscript code -

#!/bin/bash

if [ -d "/data/myfolder/testfolder" ]
then
  echo "ERROR: Directory does not exists"
  exit 1   
else
    echo "INFO: Directory exists"
    exit 0
fi
1 Answers
Related