namegen 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. #
  3. # Can a computer generate people's names that are convincing enough to fool a
  4. # human inspector?
  5. #
  6. # The Unix words file may help you wonders!
  7. #
  8. # USAGE: namegen [# of names]
  9. #
  10. # Copyright 2016 Klaus Zimmermann - https://quitter.se/kzimmermann
  11. #
  12. # This program is free software: you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation, either version 3 of the License, or
  15. # (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. #
  25. #
  26. # In Debian, this is where the file is located:
  27. DICT="/usr/share/dict/words"
  28. # How many full names do we default to?
  29. TIMES=1
  30. # Attempt to find given names and build a full name
  31. generate() {
  32. cat "$DICT" |
  33. shuf |
  34. grep [A-Z].* | # They start with capitals...
  35. sed "s/'s//g" | # But don't contain apostrophes.
  36. head -3 | # Try to string a few names to build a full name
  37. tr "\n" " " # and put them inline!
  38. echo
  39. }
  40. if [[ -n "$1" ]]
  41. then
  42. TIMES="$1"
  43. fi
  44. for i in $(seq 1 "$TIMES")
  45. do
  46. generate
  47. done