0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

シェルスクリプトで文字数を指定して文字列を初期化する方法

Posted at

文字列の長さを指定しつつ、特定の文字で初期化したい時はprintfを使うとよい

len=100
c="*"
word=$(printf "%${len}s" | tr " " "$c")

半角スペースで埋める場合はtrは不要

文字数が少ないときはfor文で連結するほうが早かったりするが、こっちのほうが1行ですむので見やすいと思う。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?