gpt4 book ai didi

bash - 通过传递参数来捕获函数?

转载 作者:行者123 更新时间:2023-11-29 08:51:05 26 4
gpt4 key购买 nike

我一直在到处搜索,我开始相信除了拥有全局变量之外别无他法,但我相信 stackoverflow.com 中的专家可能会帮助我:

在 bash 中有什么方法可以通过向函数传递参数来捕获函数吗?
例如,trap <function_name> <arg_1> <arg_2> SIGINT

最佳答案

trap 允许您指定任意命令(或命令序列),但您必须将该命令作为单个参数传递。例如,这个:

trap 'foo bar baz | bip && fred barney ; wilma' SIGINT

将运行这个:

foo bar baz | bip && fred barney ; wilma

每当 shell 接收到 SIGINT。在你的情况下,这听起来像你想要的:

trap '<function> <arg_1> <arg_2>' SIGINT

关于bash - 通过传递参数来捕获函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9504662/

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