2. Workingenvironment
On the teaching server, ictteach.its.utas.edu.au, you must make a directory named kit213script in your home directory and use this directory as your working directory for all assignment development.
1. The first time you start working on the assignment, after logging on, type the following commands ($ is the prompt, do not type that):
2. $ mkdir kit213script
Copyright By PowCoder代写 加微信 powcoder
3. $ cd kit213script
4. Every other time you log on, simply do the following and then continue working:
5. $ cd kit213script
3. Allowed Syntax/Commands
All scripts must be completed using syntax and commands discussed in past (and some future) practical classes – no additional referential syntax (that is not discussed in practicals) is allowed. This means your script solutions must not use alternative constructs and syntax e.g. solutions found through websites via google searches that use commands and shell syntax that we have not covered in the practical content, and you must not use external parties or other individuals to write the scripts for you (this is considered plagiarism and academic misconduct).
Your solution is restricted (i.e not allowed) to use the shell “builtin” binary conversion syntax e.g. echo $((2#101010101))
This restriction also extends to any other command that has not been discussed in classes – the following list shows some of the common methods (but not all) found through a brief google search – none are permitted:
awk sed printf xxd od perl ibase, obase , bc
The unit also has not discussed arrays, so syntax similar in form to powers=(128 64 32 16 8 4 2 1) #an array
for i in do
something ${powers[$i]} done
is strictly prohibited.
Instead, your solution must take an iterative (looping) approach to demonstrate your understanding of iteration and selecting individual characters from a string (a string is just a sequence of characters).
5. ScriptingTaskOverview
5.1 Scenario
There is a long tradition of producing line-based character art for a terminal using the limited character representation available in the ASCII character set. In this assessment task, you are working for a fictional company that wants to create some simple command-line “banners” that include letters, numbers and possibly patterns from pre-defined binary data that will need to be converted from decimal format. The pre-defined decimal-format data for the alphabet and numerals has been created by the company’s art department.
Each individual pattern that will ultimately be shown in the terminal window will be based on 8 rows of binary data (an 8 by 8 grid of “pixels”). As an example, consider a representation of the letter ‘A’:
Each column in the diagram above represents a power of two, and each entire row represents an 8- bit value (a byte), so the whole letter ‘A’ above uses 8 bytes for this representation. If a pixel (a particular row and column location) is white, that is the equivalent of a zero in the column for that row. If a pixel is black, it is the equivalent of a 1. In pure binary, the whole letter above is represented by the following binary patterns:
The value for the top row here is 0 in decimal. The next row has a 1 in the 25 column (32), a 1 in the 24 column (16), and a 1 in the 23 (8) column. This makes the second row (byte) value 32+16+8 = 56, the row value for the third row 64+32+8+4 = 108 etc.
5.2 Provided source “artwork” files
The entire uppercase alphabetic characters and the numeric characters 0-9 have been pre-drawn by the art department in a similar manner to that describe above. However, the data for these characters has unfortunately been generated as a series of individual files (with 8 files per character/pattern) that contain no data – instead, the encoded data binary value is part of each file’s name as a decimal number.
Continuing with the letter ‘A’ example as well as the representation for the letters ‘B’ and ‘C’ (shown below), they are represented in the provided source files using the following filenames:
5.3 Source artwork original naming convention
The format of each provided source filename is the following, which is only important if you manually copy any of the files to your own local directory:
First character
Second character
Third character
Fourth character
Fifth (and possibly sixth and seventh) characters
Last 4 characters
A literal ‘A’
The letter being represented (i.e. ‘A’ , ‘B’ , ‘C’ … ‘Z’, ‘0’ .. ‘9’)
The row number from each 8×8 grid, starting from 1
A dash (-)
The decimal value of the original byte for each row in the character’s representation grid – this ranges from 0 .. 255
A file extension – the source files use .grf
All provided source art files can be found in the following directory:
/units/kit213/assignment
Try to list the contents of that directory (with one filename per line using the -1 (minus one) option, (the $ is the prompt)):
$ ls -1 /units/kit213/assignment
You will see in the output that the files are listed in a particular order – this is the reason for the filename convention used, as ls will list the files in alphabetic and numeric order, preserving the grouping of 8 files per represented character. There are some extra “symbols” that are also included at the end that you can also use/test with if you want to – these include:
· The space character (ZA…)
· A black solid square (ZB…)
· A square shape (ZC…)
· A triangle shape (ZD…)
5.4 Copying source artwork
• A checkerboard (ZE…)
• A diamond shape (ZF…)
• Diagonal left lines (ZG…) • Diagonal right lines (ZH…)
Part of your assignment task will require you to initially copy some of the source artwork files to your own local directory for processing by the script you will be creating later, however, to simplify and aid with this copying, a command-line program is provided, called copyBinaryArt. This program will copy all of the 8 source files associated with a particular character (letter or number) or groups of letters and numbers, but during the copying will replace the first 3 letters of the source filenames with an incrementing 3-digit sequence number. This sequence number will preserve the order of the filenames when they are processed and displayed in the terminal window by your script.
copyBinaryArt can be run via the following (which will show how it is used): $ /units/kit213/assignment/copyBinaryArt
Usage: copyBinaryArt art-source art-destination starting-sequence-number string
art-source: the source directory containing the original decimal-named files
art-destination: the destination directory to copy the decimal-named files to starting-sequence-number: starting number used for first file created, incremented for each file string: the string to be converted to 8-bit decimal-named files
For example, to copy the source art files to represent the text “Hi”, the command would be: (assuming you have created a subdirectory in your current directory called “myDir”)
$ /units/kit213/assignment/copyBinaryArt /units/kit213/assignment myDir 1 “HI”
Source directory /units/kit213/assignment verified to exist! Destination directory myDir verified to exist!
The starting sequence number is 1
The string to convert is: HI
Copying files for the character ‘H’: Copying files for the character ‘I’:
After the copy has completed, the contents of MyDir would be:
002-198.grf
003-198.grf
004-198.grf
005-254.grf
006-198.grf
007-198.grf
008-198.grf
Files that represent the letter “H”
KIT213 Operating Systems 2022 Scripting Assignment
010-252.grf
011-48.grf
012-48.grf
013-48.grf
014-48.grf
015-48.grf
016-252.grf
Files that represent the letter “I”
The ultimate task for your script to complete then is to process all of the files that are contained in your local directory, converting the decimal part of each filename to binary, replacing zeros in the resulting binary values with spaces, and replacing ones with some prominent character (like an X) before displaying the result on the terminal screen. Bear in mind when your script is assessed, the marker will use completely different source files to test your script.
5.4 Source filename validity
Because of poor quality control from the art department, occasionally some files may be present in the local source directory that is used for processing (and thus testing by the marker) that do not correctly conform to the file-naming scheme. Your script will have to correctly process these files and correctly categorise (and move) them to another directory. If you have copied some valid source files to your local directory, then you will also need to manually create some invalidly named files to test your script correctly.
5.4.1 Valid filenames
Filename format: XYX-decimal.ext
➢ You are free to create your own additional artwork (using 8 filenames to represent an individual 8 by 8 grid), but your script (see below) must be able to process any validly named file that includes the naming convention described above i.e. 3-digit sequence number, dash, decimal value (0 up to 255), then a file extension (e.g. .grf).
Example: directory
any of the following would be considered potentially valid filenames in your local source (the validity will also depend on which particular filename extension has been specified)
5.4.2 Invalid filenames
Anything not fitting the patterns described above is invalid. Your script will need to categorise each invalid source filename as detailed below (in order of priority), and then copy the invalid source file to a specific subdirectory of your destination directory (see Task Requirements later).
6. Task Requirements (this is what your script must do)
1. Your script for this task must be named displayBanner.sh If your script has a different name, it will not be assessed.
2. Make sure your script is not unnecessarily complex – your script should use consistent indentation and include whitespace/blank lines (where relevant) to make the script more logical and easier for a person to read. You must also include general inline comments in the script code to indicate the purpose of more complex command combinations etc.
3. Your script must start with the following first line:
(this specifies the shell to be used to interpret the rest of the commands in the script)
4. Your script must include comments at the beginning (near the top of the script) to specify:
1. the script’s purpose,
5. Your script must accept 3 command-line arguments provided when the script is run:
1. Argument 1 – the local source directory containing the files to be processed
2. Argument 2 – the local destination directory that will be used to copy invalid
filenames to
3. Argument 3 – the file extension (without a leading dot) to be used for valid source
files (eg grf)
The directory names and the file extension that are provided by arguments 1,2 and 3 must not be ‘hardcoded’ (specified literally) in your script, i.e., their value must come from the command line arguments. If any of the 3 arguments are missing, the script should provide a usage warning message and then exit – the user must not be prompted to enter missing values when the script is running. See Example Output.
5. Near the beginning of your script, you need to check for each of the directories associated with the arguments 1 and 2 (the source directory and the destination directory):
1. Exists. If the directory does not exist, your script must display an error message and then it should exit. The directory name provided must use a relative path – see Example Output for examples.
2. Is readable, executable (for both directories) and writeable (for the destination).
i. If the directory is not readable, your script must display an error message
and then it should exit.
ii. If the directory is not writeable, your script must display an error message
and then it should exit.
iii. If the directory is not executable, your script must display an error message
and then it should exit.
6. For every file in the specified source directory, the script must:
a. For a validly named file:
i. Extract the decimal value from the filename, convert it to 8-bit binary, and then output to the terminal window the binary value but with every 0 replaced with a space character (” “) and every 1 replaced with an “X” character. The following is an example of the decimal value 59 (001110112) displayed with the space character shown below as a gray block █ for clarity purposes only):
b. For an invalidly named file that does not match the validity test:
i. display the following output to the terminal screen after all valid files have
been processed (i.e defer the output to the end of processing):
• X refers to the specific invalid category (see section 5.4.2)
ii. Move the invalid file to a subdirectory of the local destination directory that was specified as the second argument to the script, and call the subdirectory INVALIDX (the script should only create the subdirectory if it does not already exist and also only when a file in this category is found).
8. If the source directory specified as the first argument to the script contains no files: a. display the following output to the terminal screen:
• sourcedir refers to the directory name specified in argument 1
b. exit the script
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com