如何将printf与表格对齐?Shell编程 - 如何将printf对齐我的输出?
Title Author
BaokyBook Baoky2
Use basename commandUse basename command .. Baoky
我的部分代码是这样的
titlelength=${#title};
首先,我拿到冠军的长度,然后我的printf这样
titlespace=`expr 60 - titlelength`;
printf "%s %${titlespace}s\n" "$title" "$author"
但对齐是不对的,我怎么弄它工作得很好对齐
回复以下回答:
做出更改后
我所有的左侧都对齐到右侧。它似乎不工作。
要获得左对齐,请在格式前加上短划线('-')下面的答案变成'printf'%-30s%s \ n“”$ title“”$ author“'。请注意'%-30s'中的'-'。 – ntc2 2012-07-18 23:28:10