【问题标题】:How do you send output of argument to another argument你如何将参数的输出发送到另一个参数
【发布时间】:2015-02-08 04:51:06
【问题描述】:

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

【问题讨论】:

标签: bash shell awk sed output


【解决方案1】:

您可以创建一个带有三个参数的脚本,并在该脚本中调用其他三个命令,并为每个命令传递一个参数。

你会像这样使用脚本:

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

在脚本内部看起来像这样:

#!/bin/bash

commandOne "$1"
commandTwo "$2"
commandThree "$3"

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多