你如何将参数的输出发送到另一个参数

How do you send output of argument to another argument

我想创建一个需要 3 个参数的脚本。我想将第一个参数的输出发送到第二个参数,然后将最终输出重定向到一个新的 final。我该怎么做?

您可以创建一个接受三个参数的脚本,并从该脚本中调用三个其他命令,每个命令传递一个参数。

您可以像这样使用脚本:

./mainScript.sh "arg1" "arg 2" "arg3"

脚本内部看起来像这样:

#!/bin/bash

commandOne ""
commandTwo ""
commandThree ""

这是一个非常简单的例子。生产就绪代码将像这样验证参数的数量

if [ "$@" -ne "3" ]
then 
    echo "must provide three arguments"
    exit
fi