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.

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.



# Test.sh
#Run In terminal In linux
# bash Test.sh
# Example

cfile=`find -name "*.c"`
for i in $cfile
do
    echo "File : $i"
    echo "First 10 Row of File Read"
    head -10 $i
    echo "Do You Want to Remove"
    read ch
    if [ $ch="Y" -0 $ch="y" ]
    then#
        rm -i $i
    else
        echo "User not want to Deleted the file"
    fi
done




// Demo.c File Creating
#include <stdio.h>
int main()
{
  
   printf("Hello, India!");
   printf("Good Morning");
   printf("Hi.. I'm Hietsh");
   printf("What is Your Name?");
   printf("My Name Is Hit");
   printf("How Are You Hit");
   printf("I'm Fine and You");
   printf("me Good");
   printf("Where Are You");
   printf("Nice To meet Hit");
   printf("ok bye");
   return 0;


Run Test.sh File


 Deleted Demo.c File

 

 


EmoticonEmoticon