Wednesday, July 17, 2013

write a Bourne shell script that takes a directory as an argument and removes all the ordinary files under it that have .o,o.ps and .jpg extensions. if no arguement is specified the current directory is used

#!/bin/bash
################################################################
# Name: sy_6
#
# Usage: ./sy_6
#
# Author: Suresh Yadagiri
# Date:  August 06,2010
# Requirements:
#
#   write a Bourne shell script that takes a directory as an
#   argument and removes all the ordinary files under it that
#   have .o,o.ps and .jpg extensions. if no arguement is
#   specified the current directory is used
#
################################################################

function printusageinfo(){
 echo -e "\nUsage: $0 directory_name"
}

if [ $# -gt 1 ]
then
        echo "only one argument expected"
        exit 1
fi

if [ $# -eq 1 -a ! -d "$1" ]
then
        echo "$1 is not a directory or not exists"
        exit 1
fi

if [ $# = 0 ]
 then
    directory=`pwd`
 else
    directory=$1
fi

#Get file count in the given directory ; if directory
#is emptry then display appropriate message and
#quit

#echo $directory

option=`echo $directory/*.o`
rm $option 2>/dev/null

option=`echo $directory/*.ps`
rm $option  2>/dev/null

option=`echo $directory/*.jpg`
rm $option  2>/dev/null

echo " .o,.ps.jpg files removed from $directory"

No comments:

Post a Comment