【发布时间】:2020-04-12 05:08:37
【问题描述】:
我正在尝试对齐 bash 命令的输出。
这是我现在使用的命令。我使用python 执行这个bash 命令,它工作正常,所以我不打算发布那部分。
kubectl get pods -n kube-system | awk '/Completed/ {print $1}'
我将这个输出传递给一个名为output的变量
这是它的输出
akamai-1576314300-xhf78 Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
keycloak-setupbhnhc-zskhw Completed
vault-renew-tokens-1576378800-6dp98 Completed
这是我通常使用print(output) 打印时的样子
但我正在像这样使用这个output 变量。
print("here is the output: "+constant.ICON+output+")
我的输出现在看起来像这样:
???? - here is the output:
● - akamai-1576227900-wrkct Completed
akamai-1576314300-xhf78 Completed
akamai-1576400700-6m84q Completed
akamai-1576487100-bnrg7 Completed
akamai-1576573500-g48lq Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
keycloak-setupbhnhc-zskhw Completed
vault-renew-tokens-1576378800-6dp98 Completed
它没有正确对齐。
我真正想要的是这样的:
???? - here is the output:
● - akamai-1576227900-wrkct Completed
akamai-1576314300-xhf78 Completed
akamai-1576400700-6m84q Completed
akamai-1576487100-bnrg7 Completed
akamai-1576573500-g48lq Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
我该怎么做?
我正在考虑将bash 命令输出到一个数组,以便我可以正确执行此操作,但我无法将输出输出到array
有什么好的方法可以做到这一点?
【问题讨论】:
标签: python linux bash command-line