我正在嘗試將一組docker service ps呼叫對齊在一起,printf但是當我使用時它似乎將右側的東西對齊printf
for service in $(command docker service ls --format "{{.Name}}")
do
command docker service ps \
--format "table {{ .Name | printf \" .20s\" }}\t{{ .Image | printf \"@.40s\" }}\t{{ .Node | printf \" .20s\" }}\t{{.CurrentState}}\t{{.Error}}" \
$service
done
如何使printf左對齊?
uj5u.com熱心網友回復:
模板的printf功能使用fmt包。fmt包裹檔案有一個標志-:
- pad with spaces on the right rather than the left (left-justify the field)
所以而不是
{{ printf " .20s" }}
只需使用
{{ printf "%-20.20s" }}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/423080.html
標籤:
上一篇:在Golang中陷入無限回圈
