Write a simple Jeopardy! game using the Bourne-again shell (BASH) scripting language.
I've written two BASH scripts (see below) to get you started. I've also included a required Jeopardy questions database in JSON format:
The BASH script named jeopardy.sh contains incomplete code to emulate a simple Jeopardy! game. The jeopardy script reads a JSON database containing real questions and answers from the Jeopardy! game show. The jeopardy script randomly selects a question and its appropriate answer from the jeopardy JSON database.
The BASH script named compare_string_similarity.sh demonstrates how to read user input from the keyboard and compare that user input with a string.
#!/usr/bin/bash num_questions=$(jq -r '.[].question' JEOPARDY_QUESTIONS.json | wc -l) num_correct_answers=0 counter=1 while [ $counter -le 10 ] do question_number=$(shuf -n 1 -i 1-$num_questions) jeopardy_category=$(jq -r ".[$question_number].category" JEOPARDY_QUESTIONS.json) jeopardy_question=$(jq -r ".[$question_number].question" JEOPARDY_QUESTIONS.json) jeopardy_answer=$(jq -r ".[$question_number].answer" JEOPARDY_QUESTIONS.json) echo "Category: $jeopardy_category" echo "Jeopardy question: $jeopardy_question" echo "Answer: $jeopardy_answer" echo ((counter++)) done
#!/usr/bin/bash read -r -p "Enter a string or 'x' to quit: " user_input if [ "$user_input" != "x" ]; then echo "You entered: $user_input" fi while [ "$user_input" != "x" ]; do read -r -p "Enter a string or 'x' to quit: " user_input if [ "$user_input" != "x" ]; then echo "You entered: $user_input" fi done