我怎么能重复在bash一个字符? [英] How can I repeat a character in bash?

查看:252
本文介绍了我怎么能重复在bash一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能做到这一点与回声

的perl -E'说=×100


解决方案

您可以使用:

 的printf'=%。0'{} 1..100

这是如何工作:

bash扩展{} 1..100因此命令变为:

 的printf'=%。0 1 2 3 4 ... 100

我给自己定的printf的格式 =%0 这意味着它将总是打印一个 = 不管是什么说法它被赋予。因此,打印100 = 秒。

How could I do this with echo?

perl -E 'say "=" x 100'

解决方案

You can use:

printf '=%.0s' {1..100}

How this works:

Bash expands {1..100} so the command becomes:

printf '=%.0s' 1 2 3 4 ... 100

I've set printf's format to =%.0s which means that it will always print a single = no matter what argument it is given. Therefore it prints 100 =s.

这篇关于我怎么能重复在bash一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆