Bash functions
Due :

Re-write the vfile and Backup aliases as shell functions, replacing the inline ANDs and ORs with if statements. Add the features described below.

You may also rewrite the tstamp alias as a function, if desired.

Like the alias assignment, write your code in a file that can be sourced.

Put your code in a file called bashfun.sh. When you are ready to test the function definitions, source the file.

. bash-fun.sh

This means you should not call the functions inside the script file. Also, you don't need the #!/bin/bash at the beginning of the file.

Remember to documentation in your code. You need a header summariziing the overall purpose of the functions, an example of how to activate/load the functions and a list of functions in teh file.

Also, document ifs and loops. Say why, example :


1. (20 points) Define a function called getname which prompts the user for a file-name. getname should do the following : In your assignment folder :
Create a regular file called testfile.
Create a symbolic to testfile called testfile.s
Create a directory called testdir
Source the script containing the getname function. . bashfun.sh

Now test getname both with no arguments and with a filename as an argument. Use the files created above and also try ./testfile and input with other punctuation such as ? or comma.


2. (30 points) Define a function called vfile which verifies a file-name provided by the user is a regular file and is readable.

vfile does the following :


3. Write a function called Backup that backs up a specified regular file in the local directory to the $HOME/Backup folder, appending a time stamp on that backup in the process.

If invoked with no arguments, then call vfile function with no arguments.

If invoked with arguments, then call vfile with the 1st argument.

Once vfile has validated the filename, copy the file to $HOME/Backup directory. When you copy the file, use the tstamp alias to generate a time stamp, add append the time-stamp as an extension to the file-name.

Put you tstamp definition in the assignment shell script, so it is activated when the script is run.

Backup should be designed to look for a file in the current directory, so Backup should not accept path information in the filename specified.

Backup does the following :