gpt4 book ai didi

bash - 超时执行 shell 函数

转载 作者:行者123 更新时间:2023-11-29 08:40:25 24 4
gpt4 key购买 nike

为什么会这样

timeout 10s echo "foo bar" # foo bar

但这不会

function echoFooBar {
echo "foo bar"
}

echoFooBar # foo bar

timeout 10s echoFooBar # timeout: failed to run command `echoFooBar': No such file or directory

我怎样才能让它发挥作用?

最佳答案

正如 Douglas Leeder 所说,您需要一个单独的进程来发送超时信号。解决方法是将函数导出到子 shell 并手动运行子 shell。

export -f echoFooBar
timeout 10s bash -c echoFooBar

关于bash - 超时执行 shell 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9954794/

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