Skip to content

Instantly share code, notes, and snippets.

@kawaz
Created October 5, 2012 17:23
Show Gist options
  • Select an option

  • Save kawaz/3841145 to your computer and use it in GitHub Desktop.

Select an option

Save kawaz/3841145 to your computer and use it in GitHub Desktop.
カレントディレクトリからランダムに一つのファイル名を出力するbashスクリプト
#!/bin/sh
files=(.[^.]* *)
echo ${files[$RANDOM%${#files[@]}]}
@kawaz
Copy link
Author

kawaz commented Oct 5, 2012

files=(*)って空白文字含むファイルがあったらバラけちゃうのかな?と不安だったんだが、ちゃんとバラけずファイルごとに配列に入ってくれて感心した。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment