Solved UNIX ASSIGNMENT-4 New


UNIX ASSIGNMENT-4

Solved

Tutorial - 4

Subject : Unix & Shell Programming




1.     write a shell script to copy one file into other, display appropriate message if destination file already exist.
Script:
echo "Enter source filename: "
read sname
echo "Enter destination filename: "
read dname
if [ -f $sname ]
then
        if [ -f $dname ]
        then
                echo "Destination file already exists"
                echo "Do You want to overwrite the file?(y/n)"
                read ans
                if [ $ans = 'Y' -o $ans = 'y' ]
                then
                        cp $sname $dname
                        echo "Destination file overwritten"
                else
                        echo "File not copied to Destination"
                fi
        elif [ -d $dname ]
        then
                echo "Destination type is directory"
                echo "Do you want to copy file in directory?(y/n)"
                read ans
                if [ $ans = 'Y' -o $ans = 'y' ]
                then
                        cp $sname $dname
                        echo "$sname file copied to directory $dname"
                else
                        echo "File not copied to Directory"
                fi
        else
                cp $sname $dname
                echo "$dname is the new file created"
                echo "Content of $sname is copied to $dname"
        fi
else
        echo "$sname - source file doesnot exist"
        echo "Please, Enter correct source file name"
fi
echo "Program Completed"



Click below

Comments

Popular posts from this blog

Best Search Engines In The World

Documentation of Online Property Management System

Android