我试图在 bash 中以未知宽度与 printf 左对齐。
我该怎么做?
有点像这样,但这不起作用
max=<enter random number>
printf "%-${max}s|", "Instance"
重点是下面的实例将是一个未知的长度,并且长度可以是动态的。
输入示例
max=10
示例输出
Instance |
示例输入2
max=12
示例输出2
Instance |
最佳答案
您可以使用*
作为长度:
for ((max=8;max<15;max++)); do
printf "%-*s|\n" ${max} "Instance"
done
结果:
Instance|
Instance |
Instance |
Instance |
Instance |
Instance |
Instance |
关于bash - 在 bash 中与 printf 左对齐,宽度未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60959799/