小编典典

Bash读取输出?

linux

我正在Ubuntu 11.4上的一个终端上运行它。

假设我执行一个bash脚本,输出为:

Test1: Some text...
Test2: Some text...
Test3: Some text...

在同一个bash脚本中,如何将上述输出存储为一个或多个变量?

理想的解决方案是准备好在以下条件中使用:(输出的第一行将存储在$ln1等中)

if [ $ln1 = "Test1: Some text..." ] ; then

阅读 279

收藏
2020-06-07

共1个答案

小编典典

所以你要

output=$(command)
while read -r line; do
    process "$line"
done <<< "$output"

请参见Bash手册中的“此处字符串”

流程替代

while read -r line; do
    process "$line"
done < <(command)
2020-06-07