我的 BASH 脚本中有以下 printf 语句,可以很好地显示我的脚本输出:
printf "%-20s %-25s %-5s %-10s %-20s \n" $hostn $kernl $uptim $owner $team
输出如下:
Hostname1 2.6.32.12-0.7-default 307 Lastname, Firstname
Team1
Hostname2 2.6.32.12-0.7-default 270 Lastname, Firstname
Team1
Hostname3 2.6.32.12-0.7-default 298 Lastname, Firstname
Team1
Hostname4 2.6.32.12-0.7-default 271 Lastname, Firstname
Team2
我不确定为什么将团队添加到新行。我尝试添加另一个字段,但它做同样的事情:
printf "%-20s %-25s %-5s %-10s %-20s %s\n" $hostn $kernl $uptim $owner $team "test"
Hostname1 2.6.32.12-0.7-default 307 Lastname, Firstname Team1
test
Hostname2 2.6.32.12-0.7-default 270 Lastname, Firstname Team1
test
Hostname3 2.6.32.12-0.7-default 298 Lastname, Firstname Team1
test
Hostname4 2.6.32.12-0.7-default 271 Lastname, Firstname Team2
test
这些换行符来自哪里?我的 printf 格式不正确吗?