Aim:

Shell script that accepts file names specified as arguments and creates a shell script that contains this file as well as the code to recreate these files. Thus if the script generated by your script is executed, it would recreate the original files(This is same as the "bundle" script described by Brain W. Kernighan and Rob Pike in "The Unix Programming Environment", Prentice - Hall India).

Description:

$#: Contains the total number of input arguments.

$@:Contains all the input arguments

Code:

if [ $# -eq 0 ]
then
echo "error"
exit
fi
for i in $*
 do 
   echo "extracting $i file" >> f.sh
   cat $i >> f.sh
   echo "EOF" >> f.sh
 done
cat f.sh 

Compile: ./2.sh 1.c

Output:

extracting 1.c file
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
int main()
{
int pid,n,i;
char cmd[14];
system("clear");
printf("enter the no. of commands:\n");
scanf("%d",&n);
pid=fork();
if(pid)
{
 for(i=0;i<n;i++)
 {
   printf("\nEnter command:\n");
   scanf("%s",cmd);
   system (cmd);
  }
}
return 0;
}
EOF