145

条件が真の場合、スクリプト全体を強制終了せずに関数を終了するにはどうすればよいでしょうか。関数を呼び出す前に戻るだけです。

# Start script
Do scripty stuff here
Ok now lets call FUNCT
FUNCT
Here is A to come back to

function FUNCT {
  if [ blah is false ]; then
    exit the function and go up to A
  else
    keep running the function
  fi
}
4

3 に答える 3

192

使用する:

return [n]

からhelp 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.
于 2013-08-04T11:12:57.297 に答える
29

使用return演算子:

function FUNCT {
  if [ blah is false ]; then
    return 1 # or return 0, or even you can omit the argument.
  else
    keep running the function
  fi
}
于 2013-08-04T11:12:05.713 に答える