How to exit a function in bash

前端 未结 3 1772
猫巷女王i
猫巷女王i 2021-01-30 15:18

How would you exit out of a function if a condition is true without killing the whole script, just return back to before you called the function.

Example



        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 16:12

    Use:

    return [n]
    

    From help return

    return: return [n]

    Return from a shell function.
    
    Causes a function or sourced script to exit with the return value
    specified by N.  If N is omitted, the return status is that of the
    last command executed within the function or script.
    
    Exit Status:
    Returns N, or failure if the shell is not executing a function or script.
    

提交回复
热议问题