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

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.
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 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.
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...
I am attempting to write a script using bash on Linux. My program must save the...
I am attempting to write a script using bash on Linux. My program must save the long list format of the parent directory to a text file. Then, it must print how many items are in this parent directory. Then, it must sort the file in reverse order and save it to a different text file. I understand that the parent directory is accessed using cd .., and I understand that a file can be written to by echoing and...
Examine the following shell script and describe its function line-by-line: #! /bin/bash #This script backs up...
Examine the following shell script and describe its function line-by-line: #! /bin/bash #This script backs up the Oracle DB rm -f /SAN/backup-oracle* if tar -zcvf /SAN/backup-oracle- 'date +%F'.tar.gz/oracledb/* then echo "Oracle backup completed on 'date'" >>/var/log/oraclelog else echo "Oracle backup failed on 'date'" >>/var/log/oraclelog mail -s ALERT [email protected] </var/log/oraclelog fi
Write a Bash script clock.sh that once/second will print the time in the 24-hour clock format...
Write a Bash script clock.sh that once/second will print the time in the 24-hour clock format HH:MM:SS. See "man date" for a command to produce this format of time. rubric clock.sh prints h:m:s in 24-hour clock format clock.sh prints time 1/second
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of...
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of the default gateway on your machine (one way to get this is the 'default' entry, also shown as 0.0.0.0, in the output of 'ip route') and runs a ping (with a count of 5 pings) to it. Runs another count of 5 pings to the site example.com. Outputs a 1-line summary of interfaces on your machine, not including the loopback address (lo). Outputs a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT