Operating Systems and Systems Integration

Quiz 6: Shell Programming

Do not refer to any printed material. No talking or discussion is allowed until the answer sheets are all collected.

Review:

1. It is necessary to quote the parentheses ‘(...)’ in the following shell command because:

$ echo \(3 + 4\) \* 5

(A) The shell will try to start a subshell (B) The shell will terminate with a divide by zero exception (C) The precedence will be wrong, i.e., addition will not be done before multiplication (D) The shell will expand into a list of files otherwise (E) The shell will cause a sementation fault

2. Which of the following will cause a shell variable var to be defined with the value “value”?

(A) $ $var=${value}
(B) $ $var = value
(C) $ var = value
(D) $ var=value
(E) $ $var=value

3. A shell script script.sh is executed like this, and the output is shown:

$ script.sh 1 2 3 4 5 6
parameters are 1 2 3 4 5 6

The first line of the file script.sh is #! /bin/sh The second line could be:

(A) $ parameters are $* $2 $3 $4 $5 $6
(B) $ echo parameters are $0 $1 $2 $3 $4 $5
(C) $ echo parameters are $# $1 $2 $3 $4 $5
(D) $ echo parameters are $@
(E) $ echo parameters are $$ $1 $2 $3 $4 $5

Preparation:

4. This question relates to input and output in the shell:

(A) We can perform input with read, output with printf (B) We can perform input with read, output with echo (C) We often use a while loop with read to process input, one line for each iteration of the loop (D) We use redirection to put output into files (E) All the other choices are correct

5. Functions in the shell:

(A) are not actual functions, but are separate shell scripts that are loaded at run time (B) are not supported in version 2.x of Bash; (C) are less useful than in other programming languages (D) Cannot accept function parameters (E) Do not start a new process

Nick Urbanik <nicku(at)nicku.org>  ver. 1.0