Question: SHELL SCRIPTS 1 Overview In this assignment, you will demonstrate your ability to write simple shell scripts. This is a cumulative assignment that will challenge
SHELL SCRIPTS
1 Overview
In this assignment, you will demonstrate your ability to write simple shell scripts. This is a cumulative assignment that will challenge you to pull together a variety of lessons from throughout the course.
Earlier in the semester, when looking at the problems of file transfer, we discussed the difference beteween binary and ASCII files and the two styles of ASCII text files. In this assignment, you will write a script to diagnose whether a group of files are Windows-style ASCII text and, if so, will convert them to Unix-style ASCII text.
2 The Assignment
Youll be working on this assignment in 3 stages.
2.1 Stage 1
1.Create a directory ~/UnixCourse/scriptAsst.
2.Within that directory, create a shell script, isWinText.sh, that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase
Windows ASCII
if the file is an ASCII text file with CR/LF line terminators, or
Not windows text
if the file is binary or ASCII with Unix LF line terminators.
For example:
./isWinText.sh ~cs252/Assignments/ftpAsst/d3.dat Windows ASCII ./isWinText.sh /bin/cat Not windows text
Your script should not produce any other output when given a legal path to an existing file. (It may produce anything you like if given an incorrect path to a non-existent file.)
To see what kind of file you have, you can use the file command.
file filename
which was covered in the lesson on File Transfer If the output of the file command contains the phrase ASCII text and the phrase CRLF, then the file is Windows ASCII text.
Creating your own test data
-An easy way to create a file with Windows text is to log in to the CS Virtual PC Lab and use NotePad to create a file. Remember that your Z: drive in the Virtual PC Lab points to your Linux home directory, so you can easily store files created on those Windows machines in places accessible to your Linux account.
-One way to create a binary file is to again use the Virtual PC Lab to create Word or Excel documents.
-Another way to create a binary file is to compile some C++ code and use the resulting executable and/or .o files.
-An easy way to create Unix text files is to use emacs or any command that produces text output, redirected into a file, e.g.,
echo Hello > unixtext.txt
3.When you believe that you have your script working, run
~cs252/bin/scriptAsst
to check your work.
2.2 Stage 2
1.In that same directory, write a script lookForWinText.sh that takes an arbitrary number of file paths from the command line and carries out the same analysis on each one, printing a line containing the file name, a colon, a blank, and then one of the two output strings from Stage 1, for each file in the command line.
For example,
./lookForWinText.sh /usr/share/dict/words isWinText.sh /home/cs252/Assignments/ftpAsst/d3.dat /usr/share/dict/words: Not windows text isWinText.sh: Not windows text /home/cs252/Assignments/ftpAsst/d3.dat: Windows ASCII
2.When you believe that you have your script working, run
~cs252/bin/scriptAsst
again to check your work.
2.3 Stage 3
1.In that same directory, write a script fixWinText.sh that takes an arbitrary number of file paths from the command line and carries out the same analysis on each one. If a file is not Windows ASCII, your script should do nothing to it. For each file that is Windows ASCII, your script should print the message
converting fileName
and should then convert the CR/LF line terminators in that file to Unix-style LF line terminators.
For example:
cp ~cs252/Assignments/ftpAsst/d3.dat wintest.txt ./fixWinText.sh /usr/share/dict/words wintest.txt isWinText.sh converting wintest.txt
and, after the script has finished, you should be able to determine that wintest.txt is now a Unix ASCII file.
2.When you believe that you have your script working, run
~cs252/bin/scriptAsst
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
