Lab Assignment--Shell Scripts


Lab Code

To get the sample and exercise code, please use the following commands in your cs330 directory:
   curl -O -s https://www.labs.cs.uregina.ca/330/Shell/Lab11.zip
   unzip Lab11.zip

Your task is to create a bash shell script that will create a backup directory in your current directory. The name of the directory must not exist already and will be sent as a command line argument. You will create the directory and copy all the .h and .c files from your current directory into it.

An algorithm is provided below

  1. If the user has not sent one command line argument, then produce an error message indicating the usage
  2. Else if the directory already exists, then produce an error message indicating that you must provide a unique directory name
  3. Else do two things:

Sample Run:

> ./backup.sh hello there
Usage: ./backup.sh dirName
> ./backup.sh
Usage: ./backup.sh dirName
> ./backup.sh NewDir
cp: cannot stat '*.c': No such file or directory
cp: cannot stat '*.h': No such file or directory
> touch a.c b.c a.h
> ./backup.sh NewDir
Directory NewDir already exists...Please use a different name
> ./backup.sh NewDir2
> ls NewDir2
a.c  a.h  b.c

Deliverables:

Submit 2 files to URCourses:

  1. code of bash shell script
  2. script of the run showing run like sample above