A nice shell prompt that is randomly generated each time it appears. Working version.
PS1="\[\e[1;31m\]$(shuf -n 1 /usr/share/dict/words)\[\e[m\]@\[\e[1;35m\]$(shuf -n 1 /usr/share/dict/words)\[\e[m\]\$ " |
Select a random word from a textfile with bash.
ubuntu ~ $ shuf -n 1 /usr/share/dict/words plucked |
Select a random word from a text file and reverse it when it is printed to the terminal.
ubuntu ~ $ shuf -n 1 /usr/share/dict/words | rev serutnedni |
Select the random word from /usr/share/dict/words and then print it in uppercase and then reverse the output.
ubuntu ~ $ shuf -n 1 /usr/share/dict/words | tr [a-z] [A-Z] | rev S'TTOILLE |
This is another way to get random words from a file, but even on an SSD, it is very slow compared to shuf.
ubuntu ~ $ time sort -R /usr/share/dict/words | head -n 3 binomial's sunbeam lollypop's real 0m1.113s user 0m1.112s sys 0m0.001s |
Better to use shuf instead.
ubuntu ~ $ time shuf -n 4 /usr/share/dict/words handshaking fleetest deluxe Songhai's real 0m0.004s user 0m0.000s sys 0m0.003s |
Some commands are better than others for certain tasks. So do not use slow commands if there is a much faster alternative.
Get a random word and then scramble the output.
ubuntu ~ $ shuf -n 1 /usr/share/dict/words | sed 's/./&\n/g' | shuf | tr -d "\n"; echo oiudbsro |
If the user requests 6 random words instead of 1, it will merge them all together. Good way to generate a random string.
ubuntu ~ $ shuf -n 6 /usr/share/dict/words | sed 's/./&\n/g' | shuf | tr -d "\n"; echo snxssodugpr'eginlroowlmildoloitaAegaomsnsWeaqau |