2022年12月7日星期三

shell different between return and exit

1. return used in function, 
    shell will continue after return from function 

2. exit used in everywhere of shell, stop and exit shell immediately.

example:
#========================
function testreturn(){
   echo "It will return 1"
   return 1
}

function testexit(){
   echo "It will exit 1"
   exit 1 
}

echo "start..."
testreturn
echo " after return "
testexit
echo " after exit"
#========================
#run result:
start...
It will return 1
after return 
It will exit 1
==========================

没有评论: