代码之家  ›  专栏  ›  技术社区  ›  John Hunt

在bash别名中使用时,xargs命令将自动失败

  •  0
  • John Hunt  · 技术社区  · 6 年前

    git diff --name-only final-migration | xargs pstorm
    

    当我在~/.bash_配置文件中创建别名时:

    alias ropen="git diff --name-only $1 | xargs pstorm"
    

    ropen final-migration
    

    xargs pstorm 按预期工作。看起来像 xargs

    2 回复  |  直到 6 年前
        1
  •  1
  •   Socowi    6 年前

    $1 对别名有效,您的定义无效,因为 "$1" 在定义时展开。
    “1美元” echo "$1"

    alias ropen="git diff --name-only $1 | xargs pstorm"
    

    alias ropen="git diff --name-only | xargs pstorm"
    

    使用

    ropen() { git diff --name-only "$1" | xargs pstorm; }
    

    xargs git diff --names-only a b/c x/y z 参数代换 pstorm "a" "b/c" "x/y" "z" .这些文件都不存在。

    xargs -d '\n' pstorm pstorm "a b/c" "x/y z"

        2
  •  0
  •   John Hunt    6 年前

    问题出在我的Xargs版本上,它随OSX提供。通过使用GNU版本,@socowi关于使用函数的建议工作得非常完美。