Question

In: Computer Science

In many versions of unix there is an -i option for rm so that you will...

In many versions of unix there is an -i option for rm so that you will be prompted for confirmation if you are about to delete a file. Write a script called rmi which will prompt without using the -i argument

Solutions

Expert Solution

Below given is a shell script with name rmi.sh

  • Program reads a file name a command line arguments and checks whether the file with given name exis or not.
  • If exists, it will ask to delete the file
  • If the answer is yes, it will delete the file with the given name and writes the message
  • If the answer is no, It will not delete the file and writes the message
  • If the file not exist, it will write the message of file doesnot exist

-----------------------------------------------

#!/bin/bash
##below statement takes the filename from commandline
filename=$1
## below if loop checks whether the file with the given name exists or not
if [[ -f $filename ]];
then

## below line prompts for asking to delete the given file or not and reads the answer to the variable ans
read -p "Do you want to delete the file $filename ? [y/n]" ans
## below if loop checks whether the want to remove the file or not
if [[ $ans == [yY] ]];
then

## this portion deletes the file with the given name if answer is Y/y and print the message
rm "$filename"
echo "$filename deleted"
else

echo "$filename not deleted"
fi
else

##if the given file not exist, it will print the message
echo "$filename does not exist"
fi

------------------------------------------------

Output of the program is shown below


Related Solutions

You have the option to produce different versions of a product or service: high quality, or...
You have the option to produce different versions of a product or service: high quality, or low quality. The marginal cost to produce the low quality version is $3 and the marginal cost to produce the high quality version is $15. There are two types of consumers Type A and Type C with 100 consumers of each type. Each consumer will buy at most one version of the product. These consumers have the following willingness to pay: Low Quality High...
why I have seen so many percentages for okun's law. Currently I have found out many...
why I have seen so many percentages for okun's law. Currently I have found out many versions like 2 percent 3 percent 4 percent. Which figure I should use?
JAVA Generic versions of allOf() and anyOf() In this lab, you will write generic versions of...
JAVA Generic versions of allOf() and anyOf() In this lab, you will write generic versions of the allOf() and anyOf() methods you wrote in an earlier lab. Then you will take those generic versions and create versions that work with a predicate rather than direct comparison of values. Part 1 - Create generic versions of allOf() and anyOf() Recall that the integer-only versions of allOf() and anyOf() looked like this: // Returns true if any element of 'a' is equal...
The seller of an option will always __________ when the option is exercised, so: a lose;...
The seller of an option will always __________ when the option is exercised, so: a lose; the buyer of an option pays a premium to the seller of the option as compensation for the risk of loss that the option seller takes. b lose; the seller of an option will also have an option to get out of the option contract. c profit; the cost of options is very low. d profit; the seller of the option will agree to...
There are MANY versions of MySQL in production (and in some cases, test) environments. Why is...
There are MANY versions of MySQL in production (and in some cases, test) environments. Why is this? Why not just upgrade as soon as possible? Why are commands depreciated? How does this effect tutorials, books and training sites? What impact can be seen from an open-source project being under the control of a commercial company? Show some examples of what may occur. What can you do to keep YOUR database from having issues in the future? Can you future proof?...
There is many answer regarding this question on this website. So please I hope to get...
There is many answer regarding this question on this website. So please I hope to get a new clear answer E-commerce in Saudi Arabia has received a boost following the launch of several digital payment platforms in the last few years, a development that should support the growing number of online shoppers and contribute to government efforts to diversify the economy. Saudi Arabia is one of the fastest-growing markets in the Middle East for electronic payments, investments in the e-commerce...
1) There are many versions of MPEG. Mention those including their applications. 2) What is the...
1) There are many versions of MPEG. Mention those including their applications. 2) What is the difference between MPEG 2 and MPEG 4 and which one is better? 3) What do you about digital video broadcasting (DVB)? 4) Describe the data transmission using MPEG-2 and DVB.
i want a summary of the words below Versions of the Efficient Market Hypothesis It is...
i want a summary of the words below Versions of the Efficient Market Hypothesis It is common to distinguish among three versions of the EMH: the weak, semistrong, and strong forms of the hypothesis. These versions differ by their notions of what is meant by the term “all available information.” The     w e a k - f o r m    hypothesis asserts that stock prices already reflect all information that canbe derived by examining market trading data such as the...
UNIX/TERMINAL ASSIGNMENT - DIFFICULT Could you please type line by line what I should be entering...
UNIX/TERMINAL ASSIGNMENT - DIFFICULT Could you please type line by line what I should be entering in the terminal command line to complete the assignment as instructed? INSTRUCTIONS AS FOLLOWS: In this lab you will create a script to backup certain number of oldest or newest files in the current directory into a compressed archived file. The objective of this lab is to familiarize and gain proficiency with the following: • Use of command line arguments • Use of conditional...
There are so many interesting things happening in health care. So many noteworthy changes to the...
There are so many interesting things happening in health care. So many noteworthy changes to the industry are either related to financial issues or motivated by improving financial performance. This week you will have the opportunity to explore how many of the aspects of health services finance that we have explored this semester come together with current industry trends. Please find a current events (within the past year) news article from a reputable news source (MSN, New York Times, Chicago...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT