gpt4 book ai didi

bash - 如何在 bash 中退出一个函数

转载 作者:行者123 更新时间:2023-11-29 08:39:43 27 4
gpt4 key购买 nike

如果条件为真,您如何在不终止整个脚本的情况下退出函数,只需返回到调用函数之前。

例子

# 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
}

最佳答案

使用:

return [n]

来自帮助返回

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.

关于bash - 如何在 bash 中退出一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18042279/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com