Government Polytechnic, Amravati: Shell Script Program To Copy Contents of One File To Another
Government Polytechnic, Amravati: Shell Script Program To Copy Contents of One File To Another
ON
Shell script program to copy contents of one file to another.
(Sixth Semester)
In the subject of
Computer Graphics CM5460
By
1
(2020-2021)
Certificate
This is to certify that Mr. Umesh K. Bagade, Ms. Dipali R. Chandele, Mr.
Vinay S. Chpade, Mr. Kartik R. Dhoran, Ms. Samiksha S. Gedam Identity
Code. 18CM002, 18CM010, 18CM012, 18CM014, 18CM018 of Sixth Semester
Diploma in Computer Engineering has satisfactorily completed the micro-project
entitled “Shell script program to copy contents of one file to another.” in
“Linux Operating System” for the academic year 2020-2021 as prescribed in
the curriculum.
2
Annexure-I
Title of Micro Project: Shell script program to copy contents of one file to another.
3.0 Action Plan (Sequence and time required for major activities for 8 weeks)
S.N. Details of activity Planned start Planned ID .Code & Name of Team
date Finish date Members
1 Discuss and Decide the topic. 12/05/2021 12/05/2021 All Members
2 Install linux operating system 14/05/2021 16/05/2021 18CM002 (Umesh Bagade)
to run shell script program.
3 Implemented the logic for 16/05/2021 20/05/2021 18CM012 (Vinay Chopade)
case..esac statement.
4 Implemented the logic for 16/05/2021 20/05/2021 18CM018 (Samiksha Gedam)
option 1)To copy contents
from one file to another.
5 Implemented logic for option 20/05/2021 22/05/2021 18CM014 (Kartik Dhoran)
2) To remove a file
6 Implemented logic for option 22/05/2021 26/05/2021 18CM010 (Deepali Chandele)
3) To move a file and 4)Exit
7. Implemented a logic for option 27/05/2021 30/05/2021 18CM002 (Umesh Bagade)
4) Exit , combined program
3
and run the program.
4.0 Resources Required (major resources such as raw material, some machining facility, software etc)
4
Annexure-II
PART B- (Outcomes after Execution)
Micro-Project Report
Title of Micro Project: Shell script program to copy contents of one file to another.
6.0 Output
Output is attached at the last of report.
5
7.0 Skills Developed/learning out of this Micro-Project
We learned about shell scripting program to perform different operations and got
knowledge about basic commands of shell scripting.
8.0 Application of this Micro-Project
Signature of Student
6
Department Vision
Computer Department
VISION
MISSION
1. Impart need based and value based education by providing exposure of latest
tools and technologies in the area of Computer Engineering to satisfy the
stakeholders.
2. Upgrade and maintain facilities for quality technical education with continuous
effort for excellence in Computer Engineering.
3. Train students with Computer Engineering knowledge to apply it in the general
disciplines of design, deployment of software and integration of existing
technologies for E-governance and for benefit of society.
4. Provide a learning ambience to enhance innovations, problem solving skills,
leadership qualities, team spirit and ethical responsibilities.
5. Provide an academic environment and consultancy services to the industry and
society in the area of Computer Engineering
7
Theory:
1) case…esac statement:
The basic syntax of the case...esac statement is to give an expression to evaluate and
to execute several different statements based on the value of the expression.
The interpreter checks each case against the value of the expression until a match is
found. If nothing matches, a default condition will be used.
Syntax:
case word in
pattern1)
Statement(s) to be executed if pattern1 matches
;;
pattern2)
Statement(s) to be executed if pattern2 matches
;;
pattern3)
Statement(s) to be executed if pattern3 matches
;;
*)
Default condition to be executed
;;
Esac
Here the string word is compared against every pattern until a match is found. The
statement(s) following the matching pattern executes. If no matches are found, the
case statement exits without performing any action.
There is no maximum number of patterns, but the minimum is one.
8
When statement(s) part executes, the command ;; indicates that the program flow
should jump to the end of the entire case statement. This is similar to break in the C
programming language.
2) if...else...fi
The if...else...fi statement is the next form of control statement that allows Shell to
execute statements in a controlled way and make the right choice.
Syntax:
if [ expression ]
then
Statement(s) to be executed if expression is true
else
Statement(s) to be executed if expression is not true
fi
The Shell expression is evaluated in the above syntax. If the resulting value is true,
given statement(s) are executed. If the expression is false, then else block statement
will be executed.
Syntax:
cp source_file_name dest_file_name
4) Moving a file
9
To move files, use the mv command, which is similar to the cp command, except
that with mv the file is physically moved from one place to another, instead of being
duplicated, as with cp.
Syntax:
mv source_file dest_file
5) Removing a file
To remove (or delete) a file in Linux from the command line, use either the rm
(remove) or unlink command.
The unlink command allows you to remove only a single file, while with rm you
can remove multiple files at once.
Syntax:
rm file_name
10
Program:
#! \bin\sh
echo "1. To copy contents of file"
echo "2. To remove a File"
echo "3. To move a file"
echo "4. Quit"
echo "Enter your choice"
read choice
case "$choice" in
1) echo "Enter a file name to copy contents:"
read file
echo "Enter a another file name:"
read file1
if [-f $file]
then
cp $file $file1
echo "Contents of $file are copied successfully to $file1"
else
echo "$file does not exist"
fi;;
2) echo "Enter a file name to be removed: "
read file
if [-f $file]
then
rm -i $file
echo "$file successfully removed"
else
echo "$file does not exist"
fi;;
3) echo "Enter a 1st file name: "
read file
11
echo "Enter a 2nd file name: "
read file1
if [-f $file]
then
mv $file $file1
echo "Contents of $file are moved to $file1"
else
echo "$file does not exist"
fi;;
4) echo "Exit"
exit ;;
esac
:wq
Output:
12
13
Conclusion: Thus, we successfully executed a project of Shell script program to
copy contents of one file to another file.
14