Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SLG ULI101 Week 11 - Bash Scripting

Total questions: 15

Worksheet time: 14mins

Name
Class
Date
1.

What is the significance of $#?

a)

Shows the Process ID of the current script.

b)

Shows the count of the arguments passed to the script.

c)

Shows the end status of the last process to execute.

d)

Returns the current line number of the script.

2.

If funny.sh is in your current directory, how do you run it?

b)

None of the alternatives

c)
3.

What is the significance of $?

a)

It gives more details about the ? command

b)

It shows Variable $

c)

It gives the exit status of the last command that was executed.

d)

It is used with echo to show the current status of the echo command

4.

What is the significance of this line "#! /bin/bash"

a)

Is used on top of a script file to determine the output of the script

b)

Instructs the user not to use /bin/bash

c)

Determines the location of the engine which is to be used to execute the script

d)

Its used to make the script look prettier

5.

Which option will cause the echo command NOT to output a trailing newline?

a)

-e

b)

-p

c)

-n

d)

-s

6.

Which command shows if /usr/bin is in the current shell search path?

a)

cat PATH

b)

echo $PATH

c)

echo %PATH

d)

cat $PATH

e)

echo %PATH%

7.

How is it possible to determine if an executable file is a shell script which is read by Bash?

a)

The r bit is set.

b)

The file must end with .sh.

c)

The first line starts with #!/bin/bash.

d)

/bin/bash has to be run in debug mode.

e)

Scripts are never executable files.

8.

Which of the following statements may be used to access the second command line argument to a script?

a)

"$ARG2"

b)

$1

c)

"$2"

d)

"$1"

e)

'$2'

9.

What keyword is missing from the following segment of the shell script?

for i in *

_____

cat $i

done

a)

do

b)

then

c)

enod

d)

fi

e)

run

10.

What is the output of the following script?

for token in a b c

do

echo -n "$token";

done

a)

anbncn

b)

abc

c)

$token$token$token

d)

a

b

c

e)

a b c

11.

What keyword is used in a bash script to begin a loop?

a)

elif

b)

else

c)

for

d)

if

12.

A directory contains the following files:

a.txt

b.txt

c.cav

What would be the output of the following bash script?

for file in *.txt

do

echo $file

done

a)

*.txt

b)

a b

c)

c.cav

d)

a.txt

e)

a. txt

b. txt

13.

If a grep match returned two lines, what will echo $? return?

a)

0

b)

2

c)

1

d)

Nothing

14.

Using bash, check if $result is less than 20.

(a)  

15.

In bash what does fi mean or what is it for?

4 lines