Linux Essentials 2.0 & 2.21 | Basic Scripting Module 11 | Chapter 11 Exam Answers Full 100% 2023
A file begins with
- Nothing, this is a comment
- Running the script will invoke
/bin/cshto interpret the rest of the file
- The operator should not be using
- This is a Perl script
- C Shell compatibility mode is enabled
Which are appropriate editors for writing shell scripts?(choose two)
- LibreOffice Writer
nano’s commands take the form of:
- Control and another character
- Alt and another character
- Mouse clicks
- Escape followed by another character
- The F1 through F12 function keys
What does this shell script do?
FOO= /tmp/ foo if [ ! -d $FOO ] ; then mkd ir $FOO f i
- Creates /tmp/foo if it does not exist
- Makes the
/tmp/foodirectory if a file by that name exists
/tmp/foo and raises an error if there is a problem
- Nothing, since there is a problem with the conditions in the if statement
- Outputs a message to the screen
Which of the following are correct about for and while loops?(choose two)
- while loops have a test each cycle to determine if it should run again
- for loops have a test each cycle to determine if it should run again
- while loops operate over a fixed list of items
- for loops require a variable over which to iterate
- for loops operate over a fixed list of items
Given the following part of a script:
if [ - f $1 ]; then echo "I am here" fi
What is the meaning of $1?
- It is a list of files that gets interpolated
- It is a file called
- It is a special variable that indicates the exit code of the command before it
- It is a parameter to
-f, indicating the size of the file
- It is the first argument passed to the script
Given the following script that is run through ./test.sh hello goodbye:
if [ -f $2 ]; then echo "I am here" fi
When will “I am here” be printed?
- The script will always print “I am here”
- If a file called “goodbye” exists in the current directory
- If there are two files in the current directory
- If a file called “hello” exists in the current directory
What is the correct way to assign the word “Hello” to a variable?
- A = “Hello”
- echo “Hello” > A
- echo $A “Hello”
What is the correct way to save the current directory to a variable?
- pwd $A
- pwd | $A
Which shell command accepts input from the user’s keyboard?
What information is held inside
- The name of the command run
- The previous command’s exit code
- The current process ID
- The current user ID
- The number of arguments passed to the script
How would you finish your script with an exit code of 42?
- return 42
- break 42
- exit 42
ifcommand looks for what exit code to consider a condition to be true?
The number of users logged in is in a variable called
USERS. How would you test to see if there are 5 users logged in?
- test $USERS –a 5
- test $USERS,5
- test $USERS = 5
- test $USERS –eq 5
- test –f USERS=5
Given the following script:
whil e [ ! -f /tmp/ f oo ] ; do echo -n "." p r oce ss_data > / tmp/ f oo done
Which of the following are true?(choose two)
- The screen will fill with dots.
process_datawill be called at most once
- If a file called
process_datawon’t be run
/tmp/foowill be removed if it exists
process_datawill never be run
A conditional that lets you make multiple comparisons with a pattern is called:
What is the meaning of
$(( $i + 1))?
- This will return the value of the next argument to the script
- This runs the command stored in variable i
0, the loop will stop
- This will return the value of the first argument to the script
1will be added to the
How would you write a test that says “if
/tmp/foois a directory or
USERSis greater than 5″?
- test –d /tmp/foo –o $USERS –gt 5
- test /tmp/foo || $USERS > 5
- test –d /tmp/foo | $USERS > 5
- test /tmp/foo –d –o $USERS -gt 5
View all comments