将命令输出拆分为行

时间:2018-02-28 08:22:18

标签: bash scripting

我必须检查Kubernetes集群中节点的运行状况,所以为此,我使用这样的东西,输出:

$ kubectl get nodes
NAME                                 STATUS    AGE
ci-cluster-1-xpgwg744oc3y-minion-0   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-1   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-2   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-3   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-4   Ready     1d

我需要准备好数字节点,所以我需要做的就是计算就绪重合数与行数之间的关系,但是在将它分配给变量时它不会保留行尾。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

没关系,就像将它捕获到带引号的变量一样简单:

export output=$(kubectl get nodes)
echo "$output"
NAME                                 STATUS    AGE
ci-cluster-1-xpgwg744oc3y-minion-0   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-1   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-2   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-3   Ready     1d
ci-cluster-1-xpgwg744oc3y-minion-4   Ready     1d