表題のコマンドを知ったのでメモ。
■ 環境
- Amazon Linux
■ shuf
どのパッケージに入っているのか確認。
$ which shuf
/usr/bin/shuf
$ rpm -qf /usr/bin/shuf
coreutils-8.22-15.52.amzn1.x86_64
$
ヘルプを見てみる。
$ shuf --help
使用法: shuf [OPTION]... [FILE]
または: shuf -e [OPTION]... [ARG]...
または: shuf -i LO-HI [OPTION]...
Write a random permutation of the input lines to standard output.
Mandatory arguments to long options are mandatory for short options too.
-e, --echo treat each ARG as an input line
-i, --input-range=LO-HI treat each number LO through HI as an input line
-n, --head-count=COUNT output at most COUNT lines
-o, --output=FILE write result to FILE instead of standard output
--random-source=FILE get random bytes from FILE
-r, --repeat output lines can be repeated
-z, --zero-terminated end lines with 0 byte, not newline
--help この使い方を表示して終了する
--version バージョン情報を表示して終了する
ファイルの指定がなかったり, - であった場合, 標準入力から読み込みます.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
shuf の翻訳に関するバグは <http://translationproject.org/team/ja.html> に連絡してください。
完全な文書を参照する場合は info coreutils 'shuf invocation' を実行してください。
$
実際に試してみる。10から20の間の数をシャッフルする。
$ shuf -i 10-20
13
17
20
10
15
12
18
14
11
19
16
$
なるほど。ではこの中から1つを表示。
$ shuf -i 10-20 -n 1
14
$ shuf -i 10-20 -n 1
19
$ shuf -i 10-20 -n 1
11
$
実行する毎にランダムにシャッフルした結果の1つを取得できる。単純にランダムな数値を欲しい時に使えそうだ。
以上。