Ch2 Shell Scripts Exam
-
Which of the following steps is not performed while creating a shell script?
- Create a file with commands
- Make the file executable
- Login as root on the server console
- Put
#!/bin/bash
as the first line
-
The first line in a shell script reads:
#!/bin/bash
What does it signify?
- It is a comment
- Name of the editor used to create the file
- The executable (shell) to use to run the script
- The script requires root login
-
The
bash script_file
command can be used to directly execute a shell script.True or False?
- True
- False
-
Which of the following is placed before a script name to execute it from the current directory?
./
#!
!!
//
-
Instead of specifying the current directory, it is better to place the script in a location that is included in the __________ variable.
SCRIPTS
ENV
PATH
GLOBAL
-
An ideal place for a regular user (not a super user), to place their shell scripts would be:
/usr/local/sbin
/bin
/home/james/bin
/sbin
-
Use of setuid permission on scripts is the best way to specify permissions.
True or False?
- True
- False
-
A user has written a few scripts for private use. Which of the following commands should be used so that no one else has execute permission?
chmod a+x script_file
chmod -R 755 script_file
chmod u-rx script_file
chmod u+x script_file
-
Which of the following commands will produce the same result as
start=`date`
?start=%date%
start=(date)
start=date
start=$(date)
-
The __________ statement can be used to gather information from the user running the script.
seq
if
read
for
-
What will the following command do (select all that apply):
read -p “Enter data> “ test
(choose two)
- Print the input on local printer
- Work the same way as the type command
- Store user input into a variable called test
- Show a prompt along with blinking cursor
-
The command
read -p
will not capture the current position of the mouse pointer.True or False?
- True
- False
-
Conditional statements can be used to determine which of the following?
(choose three)
- If the file exists
- If two numeric values match
- If two strings match or not
- System runlevel
-
When will the condition
test -n STRING
be true?- If the length of
STRING
is zero - If the length of
STRING
is nonzero - Never
- Always
- If the length of
-
In shell scripts, the conditional statement if must always end with:
elif
False condition
fi
then
-
The return status from a command is
1.
What does this indicate?- Command did not execute successfully
- Command executed successfully
- Command is still running in the background
- Calculation done by the command yields the result
1
-
The
jamie
user already exists in the system. The commandgrep jamie /etc/passwd
displays one user record. Running theecho $?
command immediately after thegrep
command would result in what output?1
5
2
0
-
Which of the following will not handle bad user input properly:
- Checking the command’s Standard Output
- Checking the validity of user input before passing it on to the command
- Checking the value of the
$?
variable using anif
statement - Checking the return value of a command directly in the conditional part of the
if
statement
-
The
joanne
user wants an email sent when her shell script is executed successfully. Which of the following commands in the script can do this?cron
job will send an email by defaultmail root
mail joanne
echo $mail
-
The __________ statement is most useful in performing an operation on multiple items.
test
many
read
for
-
What will the following statement do?
for name in `cat /root/users`
- Report an error
- Run for two values;
cat
and/root/users
- Assign to the
name
variable each value in the specified file - Get into an infinite loop
-
The output of the command
seq 10 10 30
will be:50
10 20 30
3
10 10 30
-
The ___________ command is used to print a sequence of numbers.
series
seq
list
num
-
The statement
if [ -d file ]
will be true, if the file:- Is writable
- Exists
- Is executable
- Is a directory
-
Which of the following file
test
statement conditions is not correct?-e
filename tests if the file exists-x
filename tests a file to determine if it is executable-w
filename tests a file to determine if it is writable-d
filename tests if the file is in the current directory
-
A user wants to execute a script called
test1_script
. What type of permission does she need on thetest1_script
file?- Write only
- Read only
- Read and execute
- Read and write
-
Command substitution cannot be used to insert the output of a command as another command’s argument.
- True
- False
Subscribe
0 Comments
Newest