Shell脚本读取另一个脚本的输出

时间:2013-03-11 07:21:16

标签: shell unix

我需要编写一个shell脚本来读取另一个shell脚本(results.sh)的输出,并将结果写入一个平面文件。

基本上我们没有控制权和权限来更改results.sh但是可以访问结果。

3 个答案:

答案 0 :(得分:1)

results.sh > log.txt
mapfile b < log.txt

输出将保存到log.txt和数组变量b

答案 1 :(得分:0)

脚本a.sh

#!/usr/bin/env bash
echo $1

脚本b.sh

#!/usr/bin/env bash
while read line
do echo "read: $line"
done

试验:

chmod +x *.sh
a.sh "something" | b.sh

输出:

  

读:某事

答案 2 :(得分:0)

你尝试过使用过管道吗?

./results.sh | ./yourNewScript.sh > flat.txt

bash results.sh | bash yourNewScript.sh > flat.txt

取决于你如何运行脚本(./script需要文件具有可执行位 - chmod + x脚本)。

使用|结果直接将其输出发送到yourNewScript。 &GT;将yourNewScript的输出写入文件flat.txt