1
+ <!DOCTYPE html PUBLIC "-//IETF//DTD HTML//EN">
2
+ < html > < head >
3
+ < meta http-equiv ="content-type " content ="text/html; charset=windows-1252 ">
4
+ < title > Bash Exercises</ title >
5
+ < style >
6
+ ol .a
7
+ {
8
+ list-style-type : lower-alpha;
9
+ }
10
+ h2
11
+ {
12
+ color : red;
13
+ }
14
+ h3 {color : blue;}
15
+ table {border : solid;}
16
+ td {border : solid;}
17
+ .em { color : red; font-weight : bold }
18
+ </ style >
19
+ </ head >
20
+
21
+ < body >
22
+ < h2 > Bash Exercises</ h2 >
23
+
24
+ < p > Some of the exercises below are < span class ="em "> optional</ span >
25
+ carrying < span class ="em "> house points</ span > . You need not have to
26
+ submit these as part of your mandatory exercises. The house points
27
+ for these optional exercises are < span class ="em "> counted once per
28
+ house</ span > , and will count against the name of the student
29
+ submitting the earliest. Note that you have to submit all exercises
30
+ at once: so it will be better for your house if different members
31
+ submit different optional parts.</ p >
32
+
33
+ < p > Of course I encourage everyone to try all the exercises at leisure,
34
+ or at least learn the solutions from colleagues, after the submission
35
+ deadline.</ p >
36
+
37
+ < h3 > Bash file templates</ h3 >
38
+
39
+ < p > For each exercise, you are given a bash file template. Edit this
40
+ template for your solution. In each case, the details of what you are
41
+ supposed to do in the script is given in the template file. This is
42
+ inculcate in you the habit of documenting a script as part of the
43
+ script itself, through appropriate comments. This is also how future
44
+ exams (in bash) will appear.</ p >
45
+
46
+ < h3 > Test cases (coming up)</ h3 >
47
+
48
+ < p > In some cases, test input and the expected output for the test
49
+ input is given. Check against these. Again, future exams (in bash)
50
+ will follow this format: while evaluating, I will use a script against
51
+ one or more test inputs.</ p >
52
+
53
+ < h3 > Submission instructions (coming up)</ h3 >
54
+
55
+ < p > You are given the script prepare-upload.sh which will do the
56
+ obvious. Upload the tgz file resulting from this to moodle as your
57
+ submission.</ p >
58
+
59
+ < ol >
60
+ < li > Simple sequence of commands, simple if-then-else:
61
+ < ol class ="a ">
62
+ < li > < b > tex2pdf.sh</ b >
63
+ Script to generate dvi from latex file,
64
+ and tar the entire directory.
65
+ < br >
66
+ < i > Concepts exercised:</ i > script as a sequence of commands
67
+ </ li > < li > < b > tex2pdf-a.sh</ b >
68
+ Script to generate dvi from latex file,
69
+ and tar the entire directory, taking one argument.
70
+ < br >
71
+ < i > Concepts exercised:</ i > command line argument
72
+ </ li > < li > < b > tex2pdf-b.sh</ b >
73
+ Script to generate dvi from latex file,
74
+ and tar the entire directory, taking one argument. Check
75
+ latex compilation success. < i > Hint</ i > Learn the use of
76
+ the special shell variable "$?".
77
+ < br >
78
+ < i > Concepts exercised:</ i > checking command exit status,
79
+ if-then-else
80
+ </ li > < li > < span class ="em "> Optional [5HP]:</ span >
81
+ < b > tex2pdf-c.sh</ b >
82
+ Script to generate dvi from latex file from any location
83
+ and tar the entire directory from the parent directory, taking one argument. Check
84
+ latex compilation success. < i > Hint</ i > Learn the use of
85
+ pwd, dirname, and basename; perhaps also pushd and popd.
86
+ < br >
87
+ < i > Concepts exercised:</ i > Learning to change directories
88
+ using pushd and popd,
89
+ getting the working directory, dirname, and basename.
90
+ </ li > < li > < b > tcd.sh</ b > Timed cd.
91
+ < br >
92
+ < i > Concepts exercised:</ i > if-then-else, combining conditionals
93
+ </ li >
94
+ < li > < b > myopen.sh</ b >
95
+ This script opens a file using the right program.
96
+ < br >
97
+ < i > Concepts exercised:</ i > if-then-else, string manipulation
98
+ </ li >
99
+ < li > < span class ="em "> Optional [1HP]:</ span >
100
+ < b > myopen-a.sh</ b >
101
+ This script opens a file using the right program, and can
102
+ handle sophisticated extension possibilities
103
+ < br >
104
+ < i > Concepts exercised:</ i > if-then-else, string manipulation
105
+ </ li >
106
+ </ ol >
107
+ </ li >
108
+ < li > Involving loops:
109
+ < ol class ="a ">
110
+ < li > < b > photo-rename.sh</ b >
111
+ Write a bash script called photo-rename.sh to rename, in a given
112
+ directory, all files of the form ddmmyyyyANY.jpg to
113
+ yyyy-mm-dd-ANY.jpg< br >
114
+ Here, 'dd', 'mm', 'yyyy' correspond to the two digit date, two
115
+ digit month, and four digit year when the photo was taken, and
116
+ 'ANY' corresponds to any string (including the empty string, it
117
+ may include spaces).
118
+ The first three fields fields consist only of digits 0 to 9.< br >
119
+ Your script should ignore jpg files which are not of the form
120
+ ddmmyyyyANY.jpg< br >
121
+ Your script should take the directory name as argument; if no
122
+ argument is given, it must print the usage and exit with exit
123
+ value 1. If the given argument does not correspond to a
124
+ directory, the script must exit with exit value 2.< br >
125
+ < br >
126
+ < i > Concepts exercised:</ i > loops, learning to handle
127
+ spaces in file/dir names
128
+ </ li >
129
+ < li > < b > myopen-generic.sh</ b >
130
+ This is an enhancement to myopen.sh, making it more
131
+ generic.
132
+ < br >
133
+ < i > Concepts exercised:</ i > simple I/O redirection, string manipulation
134
+ </ li >
135
+ < li > < span class ="em "> Optional [1HP]:</ span >
136
+ < b > myopen-generic-a.sh</ b >
137
+ The configuration file should by default be myopen.cfg in the
138
+ home directory. Your script should support overriding this default
139
+ with an environment variable MYOPENCFG; if this environment variable
140
+ is set, its value should be taken as the configuration file.
141
+ < br >
142
+ < i > Concepts exercised:</ i > use of environment variables
143
+ </ li >
144
+ </ ol >
145
+ </ li >
146
+ < li > Involving pipes:
147
+ < ol class ="a ">
148
+ < li > < b > photo-dates.sh</ b >
149
+ Script to print the date and time of a photo.
150
+ < br >
151
+ < i > Concepts exercised:</ i > simple use of pipe
152
+ </ li >
153
+ < li > < span class ="em "> Optional [2HP]:</ span >
154
+ < b > photo-dates-a.sh</ b >
155
+ Script to print the date and time of several photos.
156
+ < br >
157
+ < i > Concepts exercised:</ i > simple use of pipe, loops,
158
+ string manipulation
159
+ </ li >
160
+ < li > < b > get-ip.sh</ b >
161
+ Script to get the IP address of your machine.
162
+ < br >
163
+ < i > Concepts exercised:</ i > simple use of pipe
164
+ </ li >
165
+ < li > < span class ="em "> Optional [2HP]:</ span >
166
+ < b > get-ip-a.sh</ b >
167
+ Script to print only the IP address of your machine.
168
+ < br >
169
+ < i > Concepts exercised:</ i > simple use of pipe, string
170
+ manipulation
171
+ </ li >
172
+ < li > < b > num-uploaded.sh</ b >
173
+ Script to find out how many students have submitted their
174
+ bash assignment so far.
175
+ < br >
176
+ < i > Concepts exercised:</ i > use of pipe
177
+ </ li >
178
+ < li > < span class ="em "> Optional [10HP]:</ span >
179
+ < b > tar-scp.sh</ b >
180
+ Script to tar and copy the result to another machine,
181
+ WITHOUT creating any file, in a SINGLE LINE command.
182
+ < br >
183
+ < i > Concepts exercised:</ i > forcing tar to output to
184
+ stdout, using ssh to execute a command, use of pipe
185
+ </ li >
186
+ </ ol >
187
+ </ li >
188
+ < li > Involving sed, awk: (coming up)
189
+ </ li >
190
+ </ ol >
191
+
192
+ < hr >
193
+ < address > Bhaskaran Raman</ address >
194
+ <!-- hhmts start -->
195
+ Last modified: Sat Aug 31 08:41:57 IST 2013
196
+ <!-- hhmts end -->
197
+
198
+ </ body > </ html >
0 commit comments