尝试设置for循环,其中我可以用相应的键解析值并相应地打印语句
> output.txt
Service1 Running
Service2 Running
Service3 Failed
所需输出:
Service1 is in Running state
Service2 is in Running state
Service3 is in Failed state
当时可以使用循环
while read name state; do
echo "$name is in $state state"
done < output.txt
利用printf
重用其格式规范直到输出耗尽的事实
printf "%s is in %s staten" $(cat output.txt)
如果您有bash或zsh可供使用,可以将其写得稍微简单一点:
printf "%s is in %s staten" $(<output.txt)