March 2002
Beginner
504 pages
10h 47m
English
| 1: | Add tar file extraction to the mytar script. Assume that the -x option indicates that the user wants to extract tar files and that the correct value of TARGS for extracting tar files is -xvf. |
| A1: | One correct implementation is as follows:
#!/bin/sh
USAGE="Usage: `basename $0` [-c|-t] [files|directories]"
if [ $# -lt 2 ] ; then
echo "$USAGE" ;
exit 1 ;
fi
case "$1" in
-t|-x) TARGS=${1}vf ; shift
for i in "$@" ; do
if [ -f "$i" ] ; then
FILES=`tar $TARGS "$i" 2>/dev/null`
if [ $? -eq 0 ] ; then
echo ; echo "$i" ; echo "$FILES"
else
echo "ERROR: $i not a tar file."
fi
else
echo "ERROR: $i not a file."
fi
done
;;
-c) shift ; TARGS="-cvf" ;
tar $TARGS archive.tar "$@"
;;
*) echo "$USAGE"
exit 0
;;
esac
exit $?
|
| 2: | Add the extract option to ... |
Read now
Unlock full access