Write a script that behaves both in interactive and non-interactive mode. When no arguments are supplied, it picks up each C program from current directory and lists the first 10 lines. It then prompts for deletion of the file. If the user supplies arguments with the script, then it works on those files only.

if [ $# -eq 0 ]

then

cProg=find . -name '*.c'

for i in $cProg

do

echo “first 10 lines of $i script”

head -10 $i

echo

echo -e “Do you want to delete $i file[Yes:y|No:n]::\c”

read ans

if [ $ans = “y” ]

then

rm $i

echo “file is delted”

else

echo “file is not deleted”

fi

done

else

if [ -f $1 ]

then

vi $1

else

echo “file is not present”

fi

fi

 

OUTPUT::

 

first 10 lines of ./abc.c script

#include<stdio.h>

printf

fprintf

 

Do you want to delete ./abc.c file[Yes:y|No:n]::n

file is not deleted

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.