Feb
23
2008

在 Shell 中產生隨機字串

在 Linux/Unix 的 shell 中,似乎沒有一個指令可以產生隨機字串。網上看到很多使用 PERL 寫成的 shell script,都離不開 for 還圈。這些都是很笨的做法,因為用 PERL 一句指令就可以做到了:

  1. # perl -le 'print map+(A..Z,a..z,0..9)[rand 62],0..7'

以上指令會產生 8 個位由 A-Za-z0-9 組成的隨機字串,意思很明顯吧。

Written by Chris Lam in: Linux / Unix |

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes