LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices



Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Bash quickie] Get a "random" number (larger than zero, within a range) with "shuf" only

Posted 07-31-2014 at 02:16 AM by the dsc
Updated 07-31-2014 at 02:39 AM by the dsc (deweirdifying the wording)

It always annoys me when I see things like "cat file | grep pattern | sed ..." when just "sed" would suffice, but I was guilty of using seq only to shuf random numbers when shuf can do it by itself.

shuf -n 1 -i 0-999999999

(apparently the largest number you can get is $((9999**8)) (9999^8 in bash-math), larger than that it gets negative, for some reason )


You also don't need to do some fancy "echo -e" with several "\n" (new lines) to shuf words, or anything else you could have imagined (like getting the number of variables in the array and "formatting" the echo to shuf a given number -- guilty too). Instead one can do:

shuf -n 1 -e foo bar whatever who-knew I-did-not yaddayadda "this is a phrase but counts as a word within this scheme" etc etc
Posted in Uncategorized
Views 184 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:38 AM.

Main Menu
Advertisement

Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration