Languages
[Edit]
EN

Bash - repeat a character N times

3 points
Created by:
Amir-Hashempur
607

This article will show you how to repeat a character N times in Bash.

To repeat character it is necessary to write some loop.

Quick solution (+ repeated 10 times):

or:

Note: the -n attribute prevents every character from being displayed on a newline.

 

Reusable function

Edit

In this case, we use a predefined function that repeats character.

Output:

 

Another solutions

Edit

In this section, we use a text variable that collects repeated characters.

1. Bash for loop syntax

Edit

Output:

2. C for loop syntax

Edit

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - repeat a character N times
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join