VGM
VGM

Reputation: 69

bash echo stars or hashes based on a specific number

I would like to know how can I echo the same number of # or * based of a number I type?

For example.

If I type/have 3, I would like to have as return ###.

Thank you!

Upvotes: 0

Views: 81

Answers (1)

fedorqui
fedorqui

Reputation: 290105

You can say:

$ num=3
$ printf "%0.s*" $(seq $num)
***

And if the number is fixed, use brace expansion {..}:

$ printf "%0.s*" {1..3}
***

Upvotes: 2

Related Questions