a blog distinguishes the state return value in the shell -return-break-continue-exit
First, The difference and contrast between break, continue, exit, return
Condition and loop control and program return value command Knowledge table
Command |
Description |
break n |
, the ,n |
continue n |
, the jump out of this loop, ignoring this loop's remaining code Span style= "font-family: ' The song body '; font-size:14px;" > Enter the next cycle of the loop. n n layers continue to loop |
exit n |
= shell program " Span style= "font-family: ' The song body '; font-size:14px;" >,n n can also be omitted, in the next shell $ exit n n |
return n |
In the function as the return value of the function shell $? "Receive exit n n |
Second, Break ,continue,exit function execution Flowchart
1 . The execution flow logic diagram of break functionin the loop
2 . The execution flow logic diagram of bcontinue functionin the loop
3. The execution flow logic diagram of exit function in the loop
three, using a small script to differentiate break, continue , exit , return
[[email protected] ~]# vim 3.sh
#!/bin/bash
#
#User : Mobanche
#Date : 2017-8-1
#Description :This shell script is used primarily to identify the state
# return value of a loop control that is distinguished from
# the return-break-continue-exit
if [ $# -ne 1 ]
then
echo "usage: {conntiue|break|exit|return}"
exit 1
fi
test () {
for ((i=1;i<=5;i++))
do
if [ $i -eq 3 ]
then
$*
fi
echo $i
done
echo "I am function"
}
test $*
func_ret=$?
if [ `echo $*|grep return|wc -l` -eq 1 ]
then
echo "return‘s exit status :$func_ret"
fi
echo OK
Test:
This article is from the "Last Bus" blog, be sure to keep this source http://blxueyuan.blog.51cto.com/9673381/1952770
A blog distinguishes the state return value in the shell-return-break-continue-exit