Question

In: Computer Science

The name of your bash script must be script1 and below is a description of what...

The name of your bash script must be script1 and below is a description of what it should do when executed.
  1. The script displays a message Guess, what is zip program's location
  2. Then it displays a message Enter the full path e.g. /etc/zip or /proc/bus/zip
  3. Then it reads the users response
  4. If the user's response is correct, it displays a message Great guess, zip's location is XXX, where XXX is the correct location of zip , and the script terminates.
    If the user's response is not correct, it displays a message Wrong guess and another message You guessed YYY, in fact it's location is XXX where YYY is the user's response and XXX the correct location of zip , and the script terminates.
A few useful hints:
  • What you need to know: which, echo, read, if statement, how to use backquoting
  • The command which zip returns a string containing the location of the program named zip . Example: /usr/bin/zip
  • To save the string returned by which zip , use x=`which zip`, now the variable x contains the string
  • An if statement comparing the string stored in a variable x and a string stored in a variable y has a form
    if [ "$x" == "$y" ]
    then
     (whatever you want to do here when the two strings are equal)
    else
     (whatever you want to do here when the two strings are not equal)
    fi
  • To read user's response to a variable x , use read x

Solutions

Expert Solution

echo "what is zip program's location"
echo "Enter the full path e.g. /etc/zip or /proc/bus/zip"
read x
y=`which $x`

if [ "$x" == "$y" ]
then
   echo "Great guess, zip's location is $y"
else
   echo "Wrong guess and another message You guessed $x"
fi

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and i can edit and change the answers if you argue, thanks :)


Related Solutions

Write a bash script that will allow you to: Read in your Your name Course name...
Write a bash script that will allow you to: Read in your Your name Course name and Instructor’s name Then prompt the user to enter two numbers and determine which number is greater. Ex: If 10 is entered for the first number and 3 for the second, you should output Your name Course name Instructor’s name 10 is greater than 3. If 33 is entered for the first number and 100 for the second, you shou output Your name Course...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result. Submit your program as LastName_FirstName.sh file.
create an executable bash runtests.sh as follows: The script must include the definition of a recursive...
create an executable bash runtests.sh as follows: The script must include the definition of a recursive function, explore The script prompts the user to enter a directory name and an executable name, and checks that they are both readable and executable (terminating with an error message if not). It then passes the two names to the explore function. The explore function carries out a recursive traversal of the directory and all its subdirectories, and runs the executable on each of...
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.
Use Vi text editor or ATOM to create a bash script file. Use the file name...
Use Vi text editor or ATOM to create a bash script file. Use the file name ayaan.sh. The script when ran it will execute the following commands all at once as script. Test your script file make sure it works. Here is the list of actions the script will do: It will create the following directory structure data2/new2/mondaynews off your home directory. inside the mondaynews, create 4 files sports.txt, baseball.txt, file1.txt and file2.txt. Make sure file1.txt and file2.txt are hidden...
What is a working set? What is the first line of every bash script? What is...
What is a working set? What is the first line of every bash script? What is the permission string (RWXRWXRWX format) of the number 311 What is the base directory of a file system called on windows, and on linux What does the term 'super user' mean in terms of operating systems
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...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Fully Functional Script written in BASH In this section, you will write a fully functional script...
Fully Functional Script written in BASH In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT