I have a function that is called twice with 2 different parameters. The function performs some checks and exits execution if check fails. If check succeeds, the execution continues. However in my case the execution is not exited, and it continues to call the function a second time.
I am calling the function each time and storing the returned value in variables. From what I have understood looking through answers on google and stackoverflow, the problem seems to be the fact that when I am calling the function to store it in the variable, it is running in a subshell and the "exit" just exits execution from the subshell, while the shell script continues executing. I am providing the code below:
check_profile_path() {
local profileToCheck=$1
if [ -e "$pdfToolBoxPath/used_profiles/Check$profileToCheck.kfpx" ]; then
return 0
else
outputArr[status]="failed"
outputArr[message]="profile configuration path for $profileToCheck not found at specified path"
exitCode=1
end_execution
fi
}
check_profile() {
local profileName=$1
check_profile_path $profileName
local containedText=$($someApplicationPath $somePath/used_profiles/Check$profileName.kfpx $fileToCheck)
echo "<<<<<<<<<< $profileName >>>>>>>>>>"
echo "$containedText"
echo ""
}
end_execution() {
jsonResult=$(create_json)
echo $jsonResult
exit $exitCode
}
colorSpaceProfileName="ColorSpace"
resolutionProfileName="Resolution"
colorSpaceCheckResult=$(check_profile $colorSpaceProfileName)
echo "$colorSpaceCheckResult"
resolutionCheckResult=$(check_profile $resolutionProfileName)
echo "$resolutionCheckResult"
The output I recieve from this is:
{"status":"failed","message":"profile configuration path for ColorSpace not found at specified path"}
<<<<<<<<<< Resolution >>>>>>>>>>
ProcessID 8..........
while I expect it to be just:
{"status":"failed","message":"profile configuration path for ColorSpace not found at specified path"}
I cannot set the proper syntax.. Please suggest..