正确的文字对齐 – bash

前端之家收集整理的这篇文章主要介绍了正确的文字对齐 – bash前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个问题.
我的文本应该以指定的宽度右对齐.我已设法将输出切换到所需的大小,但我把所有东西放在右侧都有问题

这是我得到的:

@H_404_4@#!/usr/local/bin/bash length=$1 file=$2 echo $1 echo -e "length = $length \t file = $file " f=`fold -w$length $file > output` while read line do echo "line is $line" done < "output"

谢谢

尝试: @H_404_4@printf "%40.40s\n" "$line"

这将使其与宽度40右对齐.如果你不想截断,请丢弃.40(感谢Dennis!):

@H_404_4@printf "%40s\n" "$line"

例如:

@H_404_4@printf "%5.5s\n" abc printf "%5.5s\n" abcdefghij printf "%5s\n" abc printf "%5s\n" abcdefghij

将打印:

@H_404_4@abc abcde abc abcdefghij

猜你在找的Bash相关文章