31.
Which line should every bash shell script start with?
- A./bin/bash
- B.#!/bin/bash
- C.!#/bin/bash
- D.!/bin/bash
- Answer & Explanation
- Report
Answer : [B]
Explanation :
Explanation :
The first line of a bash shell script contains the shebang. This defines the subshell that should be used for executing the script code. |
32.
What is the purpose of the exit 0 command that can be used at the end of a
script?
- A.It informs the parent shell that the script could be executed without any problems.
- B.It makes sure the script can be stopped properly.
- C.It is required only if a for loop has been used to close the for loop structure.
- D.It is used to terminate a conditional structure in the script.
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
The exit 0 statement at the end of a script is an optional statement to inform the parent shell that the script code was executed successfully. It is optional. |
33.
How do you stop a script to allow a user to provide input?
- A.pause
- B.break
- C.read
- D.stop
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The read statement stops a script, which allows a user to provide input. If read is used with a variable name as its argument, the user input is stored in this variable. |
34.
Which line stores the value of the first argument that was provided when
starting a script in the variable NAME?
- A.NAME = $1
- B.$1 = NAME
- C.NAME = $@
- D.NAME=$1
- Answer & Explanation
- Report
Answer : [D]
Explanation :
Explanation :
The first argument is referred to as $1. To store $1 in a variable with the name NAME, use the command NAME=$1 . Make sure that no spaces are included. In Answer A, for instance, the name of the variable that is defined is “NAME “ and not “NAME” . |
35.
What is the best way to distinguish between different arguments that have
been passed into a shell script?
- A.$?
- B.$#
- C.$*
- D.$@
- Answer & Explanation
- Report
Answer : [D]
Explanation :
Explanation :
Both $@ as $* can be used to refer to all arguments that were provided when starting a script. $@ is the preferred method though, because it enables the script to distinguish between the different individual arguments, where $* refers to all the provided arguments as one entity. |