How can I repeat a character in bash?

2019-01-02 14:25发布

How could I do this with echo?

perl -E 'say "=" x 100'

标签: bash shell echo
20条回答
回忆,回不去的记忆
2楼-- · 2019-01-02 15:23
for i in {1..100}
do
  echo -n '='
done
echo
查看更多
临风纵饮
3楼-- · 2019-01-02 15:24

Here's two interesting ways:

ubuntu@ubuntu:~$ yes = | head -10 | paste -s -d '' -
==========
ubuntu@ubuntu:~$ yes = | head -10 | tr -d "\n"
==========ubuntu@ubuntu:~$ 

Note these two are subtly different - The paste method ends in a new line. The tr method does not.

查看更多
登录 后发表回答