blob: 043c52e608aff6a1ef6382d80585e770c3f44591 (
plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# COMP-325 Assignment 2 - mo khan (3431709)
> Write shell scripts specified in problem 6 at the end of Chapter 16.
> Write shell scripts specified in problem 7 at the end of Chapter 16.
> shell scripts specified in problem 13 at the end of Chapter 16.
I have placed the Bourne shell scripts in the `bin` directory. I have
also included tests for these scripts in the `test` directory. I have
bundled a copy of [bats](https://github.com/sstephenson/bats) to make it
easier to run the tests.
```bash
$ sh ./bin/test
1..10
ok 1 testing
ok 2 invoke with a single integer
ok 3 invoke with multiple integers
ok 4 invoke with single non-numeric
ok 5 invoke with multiple non-numeric
ok 6 invoke with mixed numeric and non-numeric
ok 7 invoke with a host on the network
ok 8 invoke with a host not on the network
ok 9 invoke without a hostname argument
ok 10 invoke with multiple hostnames
```
All source code related to this assigment is stored in a private git
repository hosted on GitHub. Access is available upon request.
## Chapter 16
### Problem 6
Write a Bourne shell script that takes a list of integers as the command line argument and displays a list of their squares and the sum of the numbers in the list of squares.
```bash
$ sh bin/problem-6.sh 1 2 3 4 5
squares: 1 4 9 16 25
sum: 15
```
### Problem 7
Write a Bourne shell script that takes a machine name as an argument and displays a message informing you whether the host is on the local network.
```bash
$ sh bin/problem-7.sh localhost
localhost is on the network
$ sh bin/problem-7.sh invalid
invalid is NOT on the network
```
### Problem 13
Write a Bourne shell script for Problem 16 in Chapter 15, but use functions to implement the service code for various options.
Modify the script in the `case_demo` file in Section 15.6.6 so that it allows you to try any number of options and quits only when you use the q option.
```bash
$ sh bin/problem-13.sh
Use one of the following options:
d: To display today's date and present time
l: To see the listing of files in your present working directory
w: To see who's logged in
q: To quit this program
Enter your option and hit <Enter>:
d
Sat May 25 19:52:41 MDT 2019
Use one of the following options:
d: To display today's date and present time
l: To see the listing of files in your present working directory
w: To see who's logged in
q: To quit this program
Enter your option and hit <Enter>:
l
bin Gemfile Gemfile.lock node_modules package.json pkg Rakefile README.md README.pdf test tmp vendor yarn.lock
Use one of the following options:
d: To display today's date and present time
l: To see the listing of files in your present working directory
w: To see who's logged in
q: To quit this program
Enter your option and hit <Enter>:
w
mokha tty2 2019-05-21 20:12 (tty2)
Use one of the following options:
d: To display today's date and present time
l: To see the listing of files in your present working directory
w: To see who's logged in
q: To quit this program
Enter your option and hit <Enter>:
q
```
|