GNU/Linux >> Linux の 問題 >  >> Linux

文字列を n 回繰り返す Linux コマンド

[email protected]:~$ printf 'HelloWorld\n%.0s' {1..5}
HelloWorld
HelloWorld
HelloWorld
HelloWorld
HelloWorld
[email protected]:~$

これはかなりポータブルな昔ながらの方法です:

yes "HelloWorld" | head -n 10

これは Adrian Petrescu ののより一般的なバージョンです ブレース展開を使用して答えてください:

for i in {1..5}
do
    echo "HelloWorld"
done

これは次と同等です:

for i in 1 2 3 4 5

これは pike's のもう少し簡潔で動的なバージョンです 答え:

printf -v spaces '%*s' 10 ''; printf '%s\n' ${spaces// /ten}

すでに述べたかなりの数の良い方法。古き良き seq を忘れないで ただし:

[[email protected]]$for i in `seq 5`; do echo "Hi";done
Hi
Hi
Hi
Hi
Hi

Linux
  1. Linuxmvコマンド

  2. Linuxduコマンド

  3. Linuxipコマンド

  1. Linuxcdコマンド

  2. Linux でコマンドを自動的に繰り返す

  3. ファイルをそれ自体にn回連結するLinuxコマンド

  1. Linuxifconfigコマンド

  2. Linuxタイムコマンド

  3. LinuxでのPingコマンド