Bash functions
20 points each function
Due : 14 Nov. 2017

Re-write the vfile and Backup aliases as shell functions, replacing the inline ANDs and ORs with if statements. And adding additional error checking and features described below.

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

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

. bash-fun.sh

Remember to documentation in your code.


1. (20 points) Define a function called getname which prompts the user for a file-name. getname should do the following :
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 :