在shell脚本中创建重复字符的字符串 [英] Creating string of repeated characters in shell script
本文介绍了在shell脚本中创建重复字符的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要生成一串点(.
characters)作为变量.
I need to generate a string of dots (.
characters) as a variable.
即,在我的 Bash 脚本中,对于输入 15
,我需要生成长度为 15 的字符串:.................代码>
I.e., in my Bash script, for input 15
I need to generate this string of length 15: ...............
我需要不断地这样做.我尝试使用它作为基础(来自 Unix.com):
I need to do so variably. I tried using this as a base (from Unix.com):
for i in {1..100};do printf "%s" "#";done;printf "\n"
但是如何让 100 成为一个变量?
But how do I get the 100 to be a variable?
推荐答案
您可以从/dev/zero 获取任意数量的 NULL 字节.然后,您可以将这些转换为其他字符.下面打印16个小写的a
You can get as many NULL bytes as you want from /dev/zero. You can then turn these into other characters. The following prints 16 lowercase a's
head -c 16 < /dev/zero | tr '\0' '\141'
这篇关于在shell脚本中创建重复字符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文