【发布时间】:2012-07-18 17:46:47
【问题描述】:
如何像表格一样打印输出?
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中的-。