Learn the use of bash scripts for user input, and building simple applications f
ID: 3809893 • Letter: L
Question
Learn the use of bash scripts for user input, and building simple applications from standard Linux tools. These are the commands you will need to use. To get more information consult your textbook, the man pages, and the reference slides posted on moodle. bash builtin commands: read, while, for, case, select bash command substitution: $(...) In Lab 5 you saw how to find words that satisfy a variety of constraints in the Linux dictionary, /usr/share/dict/words. In this lab you are going to work on a simple application to be written as a script to help those who work on crossword puzzles. The script should prompt the user to enter the known and unknown letters in the word, using for each unknown letter, for example, "e-c-1-ent". After the user has entered the pattern followed by the "Enter" key, the script should list all words in the Linux dictionary that match the entered pattern. This script should give the user the option to continue or not. If yes, the script loops back and start again; if not, the script exit. The script takes no arguments and should be named crossword and saved in your ee462 directory in your AFS file space when done.Explanation / Answer
#!/bin/bash
FILENAME="/usr/share/dict/words"
choice="Y"
pattern=""
while( [ "$choice" == "Y" ] || [ "$choice" == "y" ] )
do
echo -n "Enter the pattern to be searched : "
read pattern;
pattern=$(echo "$pattern" | sed 's/-/.*/g' )
words=$(grep -iw "$pattern" $FILENAME)
echo "$words"
echo ""
echo -n 'Want to continue(Y/N) : '
read choice;
done;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.