GMa*_*ter 33 bash xargs function
这是我的代码
#!/bin/bash
showword() {
echo $1
}
echo This is a sample message | xargs -d' ' -t -n1 -P2 showword
Run Code Online (Sandbox Code Playgroud)
所以我有一个函数showword
可以回显你作为参数传递给函数的任何字符串。
然后我xargs
尝试调用该函数并将一个词一次传递给该函数,并并行运行该函数的 2 个副本。不起作用的是xargs
无法识别该功能。我怎样才能实现我想要做的事情,我怎样才能让 xargs 与函数一起工作showword
?
cuo*_*glm 40
尝试导出函数,然后在子 shell 中调用它:
showword() {
echo $1
}
export -f showword
echo This is a sample message | xargs -d' ' -t -n1 -P2 bash -c 'showword "$@"' _
Run Code Online (Sandbox Code Playgroud)