Question: Write a shell script which: 1. accepts a file name (ask the user for the file) 2. checks if file exists 3. if file exists,

Write a shell script which: 1. accepts a file name (ask the user for the file) 2. checks if file exists 3. if file exists, copy the file to the same name + .bak + the current date (if the backup file already exists ask if you want to replace it). The syntax to copy a file is:

cp file1 file2 (this will copy file1 to file2)

When done you should have the original file and one with a .bak at the end.

For example, assume the file is called test.txt.

First time you make a backup the script will rename the file to test.txt.bak

Next time you try to backup test.txt, you need to ask if the user wants to backup the file since it already exists. If the answer is "no", no backup was created. If the answer is "yes" then copy the backup to test.txt.bak.current-date (current date should be formatted to just print year-mm-dd)

The material we reviewed in class to help with this assignment is hereWrite a shell script which: 1. accepts a file name (ask theuser for the file) 2. checks if file exists 3. if file.

What to hand in?

1 file (either pdf or doc) that contains your code and the output. The output should include all different possibilities:

1. file doesnt exist so no backup. type ls -al to show no backup was created

2. file exists and no backup exists so the script creates a file.bak and prints "backup created!"

type ls -al to show backup created with .bak extension

3. file and backup already exists prompt user what to do?

if user responds "no" print no backup was created!"

if user responds "yes" print "backup created!"

type ls -al to show file.bak exists and new backup with .bak.date was not created

type ls -al to see that the backup was created with .bak.date extension

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!