wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Scripting Unit 7 and 8 Practical Revision

Total questions: 31

Worksheet time: 2hrs 48mins

Name
Class
Date
1.

How do you print the variable value. (for example: num=5)

a)

@num

b)

$num

c)

&num

d)

num

2.

Rohan wants to accept an input data from user and print it on screen. How does he do it? Choose the correct option.

a)

echo Enter data

read data

echo $data

b)

echo Enter data

input data

echo $data

c)

echo Enter data

Input data

echo @data

d)

echo

read

echo $data

3.

Avery is learning how to write scripts for automating tasks on her computer. She comes across a line at the beginning of her script that seems important. Which one of the statements is true for the first line argument in her script?

a)

First line starts with #! and this tells the compiler which interpreter to use to execute the script. and the line is #!/bin/bash

b)

First line starts with #! and this tells the compiler which interpreter to use to execute the script. and the line is #!/bash/bash

c)

First line starts with !# and this tells the compiler which interpreter to use to execute the script. and the line is #!/bin/bash

d)

First line starts with #! and this tells the compiler which interpreter to use to execute the script. and the line is #!/bash/bin

4.

Grace is writing a script for her project. What should be the first line of her script?

a)

#!/bin/bosh

b)

#!/bin/bash

c)

!#/bin/bash

d)

$#/bin/bash

5.

If you run the script as follows

./scriptName.sh Arjun Isla

What code will you be writing in your script to print these two arguments Arjun and Isla. Select correct code.

a)

Using %1 %2

b)

Using #1 #2

c)

echo $1 $2

d)

Using $0 $1

6.

In a Unix systems class, Luna learned that you should have execute permission on a file to run the script.

a)

True

b)

False

c)

I don't know

d)

We never learned

If you select this option. I will conduct special classes for you.

7.

What permission should you configure after you created the script and before you run the script.

a)

chmod u+x scriptName.sh

b)

chmod +x

c)

chmod +wr scriptName.sh

d)

None of the above

8.

The SHELL environment variable can tell you what shell program you are using on your system?

a)

True

b)

False

9.

Oliver wants to print the numbers from 1 to 5 on the screen. Which of the following commands should he use?

a)

for i in {1..5}

do

echo $i

b)

for i in {1..5}

echo $i

done

c)

for i in [1..5]

do

echo $i

done

d)

for i in {1..5}

do

echo $i

done

10.

In a classroom, Aria is organizing a group project and wants to iterate through a list of tasks. She uses the following for loop:

for i in task_list

do

execute_task

done

What is i called in the given for loop?

a)

loop variable

b)

variable

c)

environment variable

d)

special variable

11.

Jackson is organizing a countdown event where he needs to count down from 10 to 1. Select the correct script that he should use for the countdown.

a)

count=10

while [ $count -gt 0 ]

do

echo $count

((count--))

done

b)

count=10

while [ $count -le 0 ]

do

echo $count

((count==))

done

c)

count=10

while [ $count -eq 10 ]

do

echo $count

((count--))

done

d)

count=10

while [ $count -gt 10 ]

do

echo $count

((count--))

done

12.

Select the script which will print bash file name, first argument and the second argument ?

./scriptName.sh Zoe Ethan

a)

#!/bin/bash

echo $0

echo $1

echo $2

b)

#!/bin/bash

echo #0

echo $1

echo $2

c)

#!/bin/bash

echo @0

echo @1

echo @3

d)

#!/bin/bash

echo $9

echo $4

echo $3

13.

Select the script which will count number of users online.

a)

No_of_Users=$(who)

echo $No_of_Users

b)

No_of_Users=$(who | wc -l)

echo $No_of_Users

c)

No_of_Users=$(who | wc -w)

echo $No_of_Users

d)

No_of_Users=$(who | wc -c)

echo $No_of_Users

14.

Identify the error in the script given below. Select the correct line number.

count=0

while [ count -eq 5 ]

do

echo $count

((count++))

done

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

e)

Line 5

15.

Open rsyslog.conf file on server and select the correct log file path for

#The authpriv file has restricted access.

authpriv.* ______________________

a)

/etc/log/secure

b)

/var/secure

c)

/var/log/secure

d)

All of the above

16.

Open rsyslog.conf on server and select the correct path for

# Save news errors of level crit and higher in a special file.

uucp,news.crit _______________________

a)

/boot/log/spooler

b)

/var/boot/spooler

c)

/var/log/spooler

d)

/var/log/mail

17.

Select correct case statement script which print "Dog" if Dog is select and "Cat" if Cat is selected. Complete the script by selecting correct missing statement,

Complete the script so it prints "No pet selected" for any other pet animal.

echo "Enter your pet animal"

read pet

case $pet in
    Dog) echo "Dog";;
    Cat) echo "Cat";;
    *)
esac

a)

echo "No pet selected"

}

b)

echo "No pet selected"

;;

c)

echo "No pet selected"

d)

None of the above

18.

Select the correct script, which print file exist if imran.txt exist and it print file does not exist if imran.txt does not exist.

a)

if [ -f imran.txt ]

then
    echo "imran.txt File exists"
else
   fi

b)

if [ -f imran.txt ]

then
    echo "imran.txt File exists"
else "imran.txt file does not exist
   fi

c)

if [ -f imran.txt ]

then
    echo "imran.txt File exists"
else echo "imran.txt file does not exist"
   fi

d)

None of the above

19.

Select the correct script and you can use Linux server to verify your answer.

Script should print "File exist and it is a directory" if directory exist else print "File does not exist"

a)

if [ -e file.txt ]

then
    echo "File exist and it is a directory"
else "File does not exist
   fi

b)

if [ -f file.txt ]

then
    echo "File exist and it is a directory"
else "File does not exist
   f

c)

if [ -d file.txt ]

then
    echo "File exist and it is a directory"
else echo "File does not exist
   fi

d)

if [ -s file.txt ]

    echo "File exist and it is a directory"
else "File does not exist
   fi

20.

Select the script which check the FILE.txt size and print "File is not empty" else "File is empty"

a)

if [ -s file.txt ]

then
    echo "File is not empty"
else "File is empty"
   fi

b)

if [ -d file.txt ]

then
    echo "File is not empty"
else "File is empty"
   fi

c)

if [ -e file.txt ]

then
    echo "File is not empty"
else "File is empty"
   fi

d)

if [ $# file.txt ]

then
    echo "File is not empty"
else "File is empty"

21.

Select the script which print the file name (script name)

a)

echo $(basename $0)

b)

echo (basename $0)

c)

echo $(basename $1)

d)

echo (basename 0)

22.

Select the script which print all arguments on screen.

a)

echo $@

b)

echo $!

c)

echo $%

d)

echo &*

23.

Select the script which prints all the arguments as shown below and it uses a for loop to do so.

a)

for loopvar in $@

do

echo $loop

done

b)

for loopvar in $*

do

echo $loopvar

enod

c)

for loopvar in $*

do

echo $loopvar

done

d)

for loopvar in $*

do

echo loopvar

done

24.

Refer to Lab10 and understand the question:

Select the script that will find WARNINGS in dmesg file and send an email to mecorrect@gmail.com with the WARNING messages only.

a)
  • #!/bin/bash

  • result=$(grep "WARNING" /var/log/dmesg)

  • if [ $? -eq 0 ]

  • then

  • echo $result >> ~/warning.out

  • mail -s "Lab 10 : Name, id, Class" mecorrect@gmail.com < ~/warning.out

  • fi

b)
  • #!/bin/bash

  • if [ $? -eq 0 ]

  • result=$(grep "WARNING" /var/log/dmesg)

  • then

  • echo $result >> ~/warning.out

  • mail -s "Lab 10 : Name, id, Class" mecorrect@gmail.com < ~/warning.out

  • fi

c)
  • #!/bin/bash

  • if [ $? -eq 0 ]

  • then

  • echo $result >> ~/warning.out

  • mail -s "Lab 10 : Name, id, Class"

  • result=$(grep "WARNING" /var/log/dmesg)mecorrect@gmail.com < ~/warning.out

  • fi

d)
  • #!/bin/bash

  • if [ $? -eq 0 ]

  • result=$(grep "WARNING" /var/log/dmesg)mecorrect@gmail.com < ~/warning.out

  • fithen

  • echo $result >> ~/warning.out

  • mail -s "Lab 10 : Name, id, Class"

25.

Refer to your lab 8 and the activities and answer the following question.

Select the script which correct to print "I love Linux" 5 times.

a)

#!/bin/bash
for((i=0; i<6; i++))
do
echo "I love Unix!"
done

b)

#!/bin/bash
for((i=0; i<5; i++))
do
echo "I love Unix!"
done

c)

#!bin/bash
for((i=0; i<5; i++))
do
echo "I love Unix!"
done

d)

#!/bin/bash
for((i=0; i<5; i++))
do
echo "I love Unix!"
enod

26.

Select the script that print a "The Number is positive" only if the number stored in the variable is greater than 0. Which line contains an error?

 1 #!/bin/bash
 2 num=5
 3 if [$num -gt 0]
 4 then
 5  echo "Number is positive"
 6 fi

a)

1

b)

2

c)

5

d)

3

27.

During a class project, Abigail needs to count the number of lines in a file named animal.txt. What command should she use to accomplish this task? You can use a Linux server to verify your answer.

a)

cat animal.txt | wc -c

b)

wc -l animal.txt

c)

wc -l < animal.txt

d)

None of the above

28.

Daniel is working on a project in his Linux server and needs to count the number of lines in all text files in his current directory.

Select the script which prints the number of lines in all text files in his current directory.

a)

#!/bin/bash

for i in $(ls *.txt)

do

linecount=$(wc -c < $i)

echo "No of Lines: $linecount"

done

b)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(wc -l < $i)

echo "No of Lines: $linecount"

done

c)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(wc -u < $i)

echo "No of Lines: $linecount"

done

d)

#!/bin/bash

for i in `textfiles`

do

linecount=$(wc -l < $i)

echo "No of Lines: $linecount"

done

29.

Select the script that will print Number of lines of all text files in your current directory.

a)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(wc -l < $i)

echo "No of Lines: $linecount"

done

b)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(wc -l $i)

echo "No of Lines: $linecount"

done

c)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(wc -l $i)

echo "No of Lines: $linecount"

d)

#!/bin/bash

for i in `ls *.txt`

linecount=$(wc -l $i)

echo "No of Lines: $linecount"

done

30.

Below given script print number of lines that contains word "poly" on screen. Identify the lines contain error and select the line number from the given options.

line 1 - #!/bin/bash

line 2 - for $i in `ls *.txt`

line 3 - od

line 4 - linecount=$(grep poly $i | wc -l)

line 5 - echo "No of Lines contain word poly is: $linecount"

line 6 - done

a)

line 2

line 3

b)

line 4

line 4

c)

line 2

line 5

d)

line 2

line 6

31.

Select the correct script that can print number of lines that contains word "poly" in all text files in your current directory, on screen.

a)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(grep poly $i | wc -l)

echo "No of Lines contain word poly is: $linecount"

done

b)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(grep poly $i | wc -c)

echo "No of Lines contain word poly is: $linecount"

done

c)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(cat poly $i | wc -l)

echo "No of Lines contain word poly is: $linecount"

done

d)

#!/bin/bash

for i in `ls *.txt`

do

linecount=$(grep poly $i | wc -l)

echo "No of Lines contain word poly is:"

done