With your team, enter the the following BASH program in your favourite editor on our Blue Unix server (blue.cs.sonoma.edu). The program should be named "word_scramble.sh".
#!/bin/bash # Array of words for the game words=("word1" "word2" "word3" "word4" "word5" "word6" "word7" "word8" "word9" "word10" "word11" "word12" "word13" "word14" "word15" "word16" "word17" "word18" "word19" "word20") # Function to shuffle a word shuffle_word() { local word="$1" echo $(echo "$word" | fold -w1 | shuf | tr -d '\n') } # Select a random word from the array selected_word=${words[$((RANDOM % ${#words[@]}))]} # Shuffle the selected word scrambled_word=$(shuffle_word "$selected_word") # Game instructions echo "Welcome to Word Scramble!" echo "Unscramble the word: $scrambled_word" # Prompt for user input read -p "Your guess: " guess # Check if the guess is correct if [[ "$guess" == "$selected_word" ]]; then echo "Correct! Well done." else echo "Incorrect. The word was: $selected_word" fi