Question

In: Computer Science

Linux Sign into your lab account Write a bash shell script that does the following: Print...

  • Linux
  • Sign into your lab account
  • Write a bash shell script that does the following:
    • Print out a friendly welcome message
    • Ask the user for the name of their favorite animal
    • Grep that animal from a text file noises.txt
    • Tell the user what that animal says (i.e. what noise does it make)
    • If the animal does not exist ask the user what noise the animal makes
    • Store that new information in noises.txt

Solutions

Expert Solution

Please find the requested script below. Also including the screenshot of sample output .

Please provide your feedback
Thanks and Happy learning!

#!/bin/bash
#Above line sets the environment for the script to bash

echo "************** Welcome to the animal sound finder **************"
echo
echo "Enter the name of your favorite animal : "
read animal
if [ ! -z "$animal" -a "$animal" != " " ]
then
    #Check whether the file exists or not
    if [ -f ./noises.txt ]
    then
        grepResult=`grep -i "$animal" ./noises.txt | head -1`
        if [ ! -z "$grepResult" -a "$grepResult" != " " ]
        then
            animalSound=`echo $grepResult | cut -d: -f 2`
        else
            echo "Please enter the sound that $animal makes: "
            read animalSound;
            echo "$animal:$animalSound" >> ./noises.txt
        fi
        echo "$animal makes $animalSound sound."
    else
        echo "Please enter the sound that $animal makes: "
        read animalSound;
        echo "$animal:$animalSound" >> ./noises.txt
        echo "$animal makes $animalSound sound."
    fi
else
    echo "Sorry, You have entered an invalid animal name!"
fi

Related Solutions

Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances of a given string within a file. The scripts takes two arguments: the name of the file to check and the string to count occurances of. If the file is not found (or not readable), the script should print the error message Cannot access file and exit with code -1. Otherwise, the script should print the number of occurances of the given string and...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
write a bash shell script using the for-loop construct that counts the number of files and...
write a bash shell script using the for-loop construct that counts the number of files and directories looping through the files in the directory name provided by the user on a prompt by the script and prints "TOO many files" is the count of files is larger than a random number it generates between 20 and 40
Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
Write a BASH shell script (see the Important Notes section) that acts as a DOS command...
Write a BASH shell script (see the Important Notes section) that acts as a DOS command interpreter (the user enters the DOS command and the script executes the corresponding Linux command). The script should loop continuously until the user enters the QUIT command Prior to accepting a command, display a prompt containing your first name and the greater than symbol (>) Example prompt: linux> The DOS command, and any arguments, should be stored in variables $command – the DOS command...
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in...
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in the current directory whose names end in 't' or 'z'. For such files only, your program should list certain LINES of the file(s). These lines are those that have at least 4 x's somewhere in the line. Note that the x's may be upper- or lower-case, and may be separated by other characters; so the following 3 lines DO match: XXxX and more things...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT