Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash
- # sat3310 - lab03
- # created by bcstinch@mtu.edu
- # 2/21/2018
- # Variables
- declare -a nounarray
- declare -a anounarray
- dir="/root/Documents/labs/lab05/data/"
- nounfile="nouns.txt"
- anounfile="agentnouns.txt"
- declare -i nouncount
- declare -i anouncount
- # Main
- # List files
- pwd $dir
- # Put words into a list
- readarray -t nounarray < $dir$nounfile
- readarray -t anounarray < $dir$anounfile
- # Count words
- nouncount=${#nounarray[@]}
- anouncount=${#anounarray[@]}
- # Print counts
- echo "There are $nouncount nouns in $nounfile"
- echo "There are $anouncount agent nouns in $anounfile"
- # Random select
- randomnoun=${nounarray[RANDOM %nouncount]}
- randomanoun=${anounarray[RANDOM %anouncount]}
- # Print words
- echo "A random noun is $randomnoun"
- echo "A random agent noun is $randomanoun"
- # Done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement