I want to clean up some of my code, for that I want to clean the check return code status check I make after each command. If the command fails I return mid function to the parent function. If I'll take this code inside a function then nothing happens as the return command will be inside the new-child function.
Sure gald for some thoughts.
Current status:
a(){
for i in $(cat file.txt)
do
scp $i hostb:/tmp/
if [ $? -ne 0 ]
then
print_failed "SCP failed."
return 1
fi
done
}
Desired:
a(){
for i in $(cat file.txt)
do
scp $i hostb:/tmp/
# continue as usuall unless return code is not 0
check_status $?
done
}
check_status(){
if [ $1 -ne 0 ]
then
print_failed "SCP failed."
return 1
fi
}