Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/bash
  2.  
  3. # sat3310 - lab03
  4. # created by bcstinch@mtu.edu
  5. # 2/21/2018
  6.  
  7. # Variables
  8.  
  9. declare -a nounarray
  10. declare -a anounarray
  11. dir="/root/Documents/labs/lab05/data/"
  12. nounfile="nouns.txt"
  13. anounfile="agentnouns.txt"
  14. declare -i nouncount
  15. declare -i anouncount
  16.  
  17.  
  18. # Main
  19.  
  20. # List files
  21.  
  22. pwd $dir
  23.  
  24. # Put words into a list
  25.  
  26. readarray -t nounarray < $dir$nounfile
  27. readarray -t anounarray < $dir$anounfile
  28.  
  29. # Count words
  30.  
  31. nouncount=${#nounarray[@]}
  32. anouncount=${#anounarray[@]}
  33.  
  34. # Print counts
  35.  
  36. echo "There are $nouncount nouns in $nounfile"
  37. echo "There are $anouncount agent nouns in $anounfile"
  38.  
  39. # Random select
  40.  
  41. randomnoun=${nounarray[RANDOM %nouncount]}
  42. randomanoun=${anounarray[RANDOM %anouncount]}
  43.  
  44. # Print words
  45.  
  46. echo "A random noun is $randomnoun"
  47. echo "A random agent noun is $randomanoun"
  48.  
  49. # Done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement