wKa*_*vey 12 linux bash terminal ubuntu
我在Ubuntu 11.4的终端上运行它.
假设我执行了一个bash脚本,输出是:
Test1: Some text...
Test2: Some text...
Test3: Some text...
Run Code Online (Sandbox Code Playgroud)
在同一个bash脚本中,我如何将上面的输出存储为一个或多个变量?
理想的解决方案是准备好在条件中使用,如下所示:(输出的第一行将存储在$ln1等等中)
if [ $ln1 = "Test1: Some text..." ] ; then
Run Code Online (Sandbox Code Playgroud)
gle*_*man 32
所以你要
output=$(command)
while read -r line; do
process "$line"
done <<< "$output"
Run Code Online (Sandbox Code Playgroud)
请参阅Bash手册中的"Here strings" .
或过程替代
while read -r line; do
process "$line"
done < <(command)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42719 次 |
| 最近记录: |