Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在bash脚本中将管道输入包装到标准输出?_Bash_Stdout_Pipe_Stdin - Fatal编程技术网

如何在bash脚本中将管道输入包装到标准输出?

如何在bash脚本中将管道输入包装到标准输出?,bash,stdout,pipe,stdin,Bash,Stdout,Pipe,Stdin,我想编写一个bash脚本,用一些文本包装管道输入 基于谷歌搜索并尝试从示例中挑选。 以下是迄今为止我所拥有的,但不起作用的: #!/bin/sh if readlink /proc/$$/fd/0 | grep -q "^pipe:"; then echo "{ "template":{"name":"contact sheet template","root":"root","parameters": ["pages"]},"pages":" cat echo "}"

我想编写一个bash脚本,用一些文本包装管道输入

基于谷歌搜索并尝试从示例中挑选。 以下是迄今为止我所拥有的,但不起作用的:

#!/bin/sh

if readlink /proc/$$/fd/0 | grep -q "^pipe:"; then
    echo "{ "template":{"name":"contact sheet template","root":"root","parameters": ["pages"]},"pages":"
    cat
    echo "}"
fi
我从另一个程序接收到一个JSON列表作为管道输入,我想在将结果管道传输到下一个程序之前,先输出上面的文本

program_1 | wrapper.sh | program_2 > outputfile
但是它没有输出任何东西


有没有更精通bash的人能为我指出正确的方向?

我个人会这样搜索:

myscript.sh


就我个人而言,我将以这种方式进行搜索:

myscript.sh


您的意思是您的脚本正在从管道读取标准输入,例如

$ other-process | my-script
?

然后脚本中的命令将简单地从管道继承标准输入

#!/bin/sh

# Output preamble
cat <<EOF
{ "template":{"name":"contact sheet template","root":"root","parameters": ["pages"]},"pages":
EOF

cat   # This reads from standard input inherited from your script

# Output the closing
cat <<EOF
}
EOF

您的意思是您的脚本正在从管道读取标准输入,例如

$ other-process | my-script
?

然后脚本中的命令将简单地从管道继承标准输入

#!/bin/sh

# Output preamble
cat <<EOF
{ "template":{"name":"contact sheet template","root":"root","parameters": ["pages"]},"pages":
EOF

cat   # This reads from standard input inherited from your script

# Output the closing
cat <<EOF
}
EOF

它应该是什么猫?输入来自何处?Jarrod-您能提供一个示例,说明您发送的内容以及您希望输出的内容吗?它应该是什么?输入是从哪里来的?Jarrod-您能提供一个示例,说明您发送的内容以及希望输出的内容吗?