gpt4 book ai didi

bash - 将函数从 zsh 导出到 bash 以便在 gnu parallel 中使用

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

如何从 zsh 导出一个函数,以便我可以在 gnu 中并行使用它?

例子:

function my_func(){ echo $1;}
export -f my_func
parallel "my_func {}" ::: 1 2

在bash中会输出

1
2

而在 zsh 中它会输出错误信息

/bin/bash: my_func: command not found
/bin/bash: my_func: command not found

最佳答案

zsh 没有导出函数的概念。 export -f somefunc 将打印函数定义,它不会导出函数。

相反,您可以依赖 bash 函数导出为以 () 开头的常规变量这一事实:

export my_func='() { echo "$1"; }'
parallel --gnu "my_func {}" ::: 1 2

关于bash - 将函数从 zsh 导出到 bash 以便在 gnu parallel 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22738425/

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