
Bash
How to Repeat a Character or String N Times in Bash
Repeat a character or string N times in Bash with printf, brace expansion, a loop or seq, and learn why a variable inside braces does not work.
5 min read
Tag
4 posts

Repeat a character or string N times in Bash with printf, brace expansion, a loop or seq, and learn why a variable inside braces does not work.

Pad a string in Bash with printf width flags for zeros and spaces, left or right alignment, dynamic widths, and a note on why padding multibyte text drifts.

Reverse a string in pure Bash with a loop and substring expansion, compare it with rev and tac, and see where multibyte characters change the result.

Compare strings in Bash with [[ ]], quote both sides, tell = from == apart, match patterns and regexes, and avoid the empty-variable errors that break tests.