tar command. Your script should display a prompt, read commands from
STDIN and process those commands. The idea is to provide a simple user
interface around the tar command to help people who don't want to have to
remember the cryptic syntax to the tar command. Your script should
use the tar command!
| !Important! Your shell script should read commands the user types in from STDIN, this means that we could also feed your script input from a file (a sequence of commands could be stored in a file and fed to your script). |
You can write the script using sh, bash or
csh - you cannot use awk or
perl.
The name of the script should be itar ( stands for interactive
tar) and should accept a single required command line paramater
that indicates the tarfile that should be used. If the file specified
on the command line does not exist your script should create it.
The commands you need to support are listed below, the general idea is to allow the user to list the files in a tar archive, to add new files to the archive and to extract files from the archive.
| Command Name | Resulting operation |
|---|---|
| help or ? | Print a list of valid commands |
| run | runs a unix command (could be any command!) |
| list | Prints out a list of the files in the tar archive |
| add files... | adds the named files to the archive |
| quit | quits the program |
| extract files... | extracts the named files from the tar archive |
Your script should print out a prompt whenever it is ready to accept a command from STDIN, this prompt must include the name of the current tarfile and the number of files in the tarfile.
Here is what a sample session might look like (this one creates a tar archive named proj.tar):
> itar proj.tar no such file proj.tar - creating empty archive ==== itar v1.0 archive: proj.tar #files:0==== tarman > help run list extract add help quit ? ==== itar v1.0 archive: proj.tar #files:0==== tarman > list The files in the archive proj.tar are: ==== itar v1.0 archive: proj.tar #files:0==== tarman > run ls -l total 69 -rw-rw---- 1 hollingd grads 2523 Feb 12 11:40 #parse.c# drwxrwx--x 3 hollingd grads 512 Feb 12 11:56 . drwxrwx--x 3 hollingd grads 512 Feb 12 11:54 .. -rw------- 1 hollingd grads 325 Feb 12 11:40 Makefile -rw------- 1 hollingd grads 2239 Feb 12 11:40 auth.c -rw--w---- 1 hollingd grads 2348 Feb 12 11:40 auth.o drwxrwx--x 2 hollingd grads 512 Feb 12 11:54 new -rw-rw---- 1 hollingd grads 2369 Feb 12 11:40 parse.c -rw-rw---- 1 hollingd grads 0 Feb 12 11:56 proj.tar -rwxrwx--x 1 hollingd grads 10720 Feb 12 11:40 proxy -rw------- 1 hollingd grads 8789 Feb 12 11:40 proxy.c -rw-rw---- 1 hollingd grads 6272 Feb 12 11:40 proxy.o -rwx-wx--x 1 hollingd grads 9600 Feb 12 11:40 proxy1 -rw------- 1 hollingd grads 7017 Feb 12 11:40 proxy1.c -rw--w---- 1 hollingd grads 4888 Feb 12 11:40 proxy1.o -rw------- 1 hollingd grads 746 Feb 12 11:40 readline.c -rw------- 1 hollingd grads 83 Feb 12 11:40 readline.h -rw--w---- 1 hollingd grads 1212 Feb 12 11:40 readline.o ==== itar v1.0 archive: proj.tar #files:0==== tarman > add *.c adding *.c to tarfile auth.c parse.c proxy.c proxy1.c readline.c ==== itar v1.0 archive: proj.tar #files:5==== tarman > list The files in the archive proj.tar are: auth.c parse.c proxy.c proxy1.c readline.c ==== itar v1.0 archive: proj.tar #files:5==== tarman > add *.h adding *.h to tarfile readline.h ==== itar v1.0 archive: proj.tar #files:6==== tarman > list The files in the archive proj.tar are: auth.c parse.c proxy.c proxy1.c readline.c readline.h ==== itar v1.0 archive: proj.tar #files:6==== tarman > list The files in the archive proj.tar are: parse.c proxy.c proxy1.c readline.c readline.h ==== itar v1.0 archive: proj.tar #files:5==== tarman > quit |
Here is another example session, this one involves the extraction of some files from the tarfile built above:
>itar ../proj.tar ==== itar v1.0 archive: ../proj.tar #files:5==== tarman > list The files in the archive ../proj.tar are: parse.c proxy.c proxy1.c readline.c readline.h ==== itar v1.0 archive: ../proj.tar #files:5==== tarman > run ls ==== itar v1.0 archive: ../proj.tar #files:5==== tarman > extract parse.c proxy.c extracting parse.c proxy.c from ../proj.tar parse.c proxy.c ==== itar v1.0 archive: ../proj.tar #files:5==== tarman > run ls -al total 14 drwxrwx--x 2 hollingd grads 512 Feb 12 12:12 . drwxrwx--x 3 hollingd grads 512 Feb 12 11:56 .. -rw-rw---- 1 hollingd grads 2369 Feb 12 11:40 parse.c -rw------- 1 hollingd grads 8789 Feb 12 11:40 proxy.c ==== itar v1.0 archive: ../proj.tar #files:5==== tarman > quit |
Feel free to include the results of testing that you did (sample output), a description of any problems you had or anything else you think might help us. Please also indicate what flavor of unix you used to develop your script (Sun, Linux, BSD, SGI, IBM, ...).
read,
expr, select, function.
echo -n does not output a newline.