我一直在到处搜索,我开始相信除了拥有全局变量外,别无选择,但我相信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/