-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkpics
68 lines (53 loc) · 1.37 KB
/
mkpics
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
# check whter the first input is a positive integer
if [ $1 -gt 0 ]
then
# if is, record and pop it
num_cols=$1
shift
else
# if not, give an error message and exit in an proper situation
echo "$1: is not a positive int" 1>&2
exit 1
fi
# print out the beginning several lines
echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">"
echo "<html>"
echo " <head>"
echo " <title>Pictures</title>"
echo " </head>"
echo
echo " <body>"
echo " <h1>Pictures</h1>"
echo "<table>"
while [ "$1" != '' ]
do
# print the prefix for a new row
echo " <tr>"
# i is a counter used to count num of columns we filled
i=0
while ([ "$1" != '' ] && [ "$i" -lt "$num_cols" ])
do
# get the type of that parameter
type=`file -b "$1" | cut -c 1-4`
# if the file is JPEG type
if [ "$type" = "JPEG" ]
then
# a way to print out a string with '"'s inside
echo " <td><img src=\"$1\" height=100></td>"
# increment counter
i=`expr $i + 1`
# if the file is another type or not exist
else
# give an error message and keep running
echo "error: "$1": is not a valid JPEG file" 1>&2
fi
# pop the used parameter
shift
done
# print the suffix for that row
echo " </tr>"
done
# print out the last several lines
echo "</table>"
echo " </body> </html>"