A blog distinguishes the state return value in the shell-return-break-continue-exit

Source: Internet
Author: User



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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.