免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: super_fan_cu
打印 上一主题 下一主题

如何才能将输出,变为右对齐? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2012-03-16 23:56 |只看该作者
右对齐用printf吧……
可以用左对齐吗?

论坛徽章:
0
12 [报告]
发表于 2012-03-17 17:39 |只看该作者
  echo "$each_file    "  "$Sh    "  "$h1    " "$h2     "  "$vh     "   "$Se    "   "$e1    "   "$e2    "   "$ve   
在shell脚本中 使用printf 输出不就可以很好地控制格式了么
比如
$ cat print.sh
#!/bin/bash
AAA="hello"
BBB="asdasfss"
CCC="asdfasfsdf"
printf "%20s%20s%20s\n" "$AAA" "$BBB" "$CCC"
printf "%20s%20s%20s\n" "$BBB" "$AAA" "$CCC"
printf "%20s%20s%20s\n" "$AAA" "$CCC" "$BBB"
$ sh ./print.sh
               hello            asdasfss          asdfasfsdf
            asdasfss               hello          asdfasfsdf
               hello          asdfasfsdf            asdasfss

论坛徽章:
0
13 [报告]
发表于 2012-03-18 10:24 |只看该作者
sncchen 发表于 2012-03-17 17:39
echo "$each_file    "  "$Sh    "  "$h1    " "$h2     "  "$vh     "   "$Se    "   "$e1    "   "$e2  ...

多谢了,对shell不是很熟,小白一个,所以上面的高手虽然指点了,还是不懂!

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
14 [报告]
发表于 2012-03-19 11:17 |只看该作者
回复 11# xiaopan3322


yes
man 3 printf
      ...
       -      The  converted  value is to be left adjusted on the field bound‐
              ary.  (The default is right justification.)
Except for  n  con‐
              versions,  the  converted  value  is  padded  on  the right with
              blanks, rather than on the left with blanks or zeros.  A - over‐
              rides a 0 if both are given.
      ...

论坛徽章:
0
15 [报告]
发表于 2012-03-19 21:55 |只看该作者
jason680 发表于 2012-03-19 11:17
回复 11# xiaopan3322



我的意思是,问楼主可否用左对齐,左对齐的话直接用column了……
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP