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...
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...
I am trying to create a makefile for the following program in Unix. The C++ program...
I am trying to create a makefile for the following program in Unix. The C++ program I am trying to run is presented here. I was wondering if you could help me create a makefile for the following C++ file in Unix and show screenshots of the process? I am doing this all in blue on putty and not in Ubuntu, so i don't have the luxury of viewing the files on my computer, or I don't know how to...
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...
Option A – For 30 days, I give you an amount of money to save. On...
Option A – For 30 days, I give you an amount of money to save. On day 1, I will give you $0.01. On day 2, I will double that and give you $0.02. You now have $0.03. On day 3, I will double the previous day and give you $0.04. You now have $0.07. This pattern will continue until 30 days have passed. Option B – For 30 days, I will give you $10,000 to save. Each day I...
You are a customer. Are you loyal to any organization? If so, how many bad experiences...
You are a customer. Are you loyal to any organization? If so, how many bad experiences will it take to overcome your loyalty? Have you ever decided to withhold your business from a store, restaurant, or other service provider based on poor service? Do you usually give an organization more than one chance to win your business, or is one bad experience all it takes to turn you off?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT