xargs 不适用于内置的 shell 函数 [英] xargs not working with built in shell functions

查看:68
本文介绍了xargs 不适用于内置的 shell 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加快数据库的处理速度.我迁移到 xargs.但我被严重卡住了.如果 xargs 调用的命令不是内置命令,则将参数列表传递给 xargs 将不起作用.我不知道为什么.这是我的代码:

I am trying to speed up the processing of a database. I migrated towards xargs. But I'm seriously stuck. Piping a list of arguments to xargs does not work if the command invoked by xargs isn't a built in. I can't figure out why. Here is my code:

#!/bin/bash

list='foo
bar'

test(){
    echo "$1" 
}

echo "$list" | tr '\012' '\000' | xargs -0 -n1 -I '{}' 'test' {}

所以根本没有输出.并且测试函数永远不会被执行.但是,如果我将xargs"命令中的test"替换为echo"或printf",它就可以正常工作.

So there is no output at all. And test function never gets executed. But if I replace "test" in the "xargs" command with "echo" or "printf" it works fine.

推荐答案

xargs 将可执行文件作为参数(包括自定义脚本)而不是环境中定义的函数.

xargs takes an executable as an argument (including custom scripts) rather than a function defined in the environment.

将您的代码移至脚本或使用 xargs 将参数传递给外部命令.

Either move your code to a script or use xargs to pass arguments to an external command.

这篇关于xargs 不适用于内置的 shell 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆