readyforhires

Intermediate Shell Scripting test (Intermediate)

30 questions · 35 minutes · Free

Functions, text processing, exit codes and cron.

Take the Intermediate Shell Scripting test

What it covers

Interview format

Earn a certificate

The Intermediate Shell Scripting test is one of the 8 tests of the DevOps Engineer: Intermediate learning path. Pass it and the other 7 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.

Sample learning path certificate for DevOps Engineer: Intermediate, made out to “Your name” and marked SAMPLE
Pass with 70% or more to earn a verifiable certificate. This is a sample: yours carries your name, the date you earned it and its own verify code.

Sample questions

5 sample questions from the Intermediate Shell Scripting test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.

  1. What determines the exit status of a function in a shell script?

    1. The exit status of the function will always be 0, regardless of the commands inside the function.
    2. The exit status of the function will be the exit status of the last command executed inside the function.
    3. The exit status of the function will be the exit status of the first command executed inside the function.
    4. The exit status of the function will be undefined if any command inside the function fails.

    Answer: B. The exit status of the function will be the exit status of the last command executed inside the function.

    In shell scripting, the exit status of a function is determined by the exit status of the last command executed within the function. If a function contains multiple commands, only the exit status of the last one is propagated. This behavior is consistent regardless of whether the function is defined with or without the 'set -e' option, as 'set -e' only affects the script's behavior on encountering a non-zero exit status, not the propagation of exit statuses from functions.

  2. What is the behavior of a shell script when the 'set -e' option is enabled?

    1. Only the last command's exit status is checked.
    2. The script will exit immediately if any command exits with a non-zero status.
    3. The script will continue executing even if a command fails.
    4. The script will ignore all exit statuses and continue.

    Answer: B. The script will exit immediately if any command exits with a non-zero status.

    When the 'set -e' option is enabled in a shell script, the script will exit immediately if any command exits with a non-zero status. This is a key feature of 'set -e' and helps in making scripts more robust by ensuring that failures are caught early.

  3. Which of the following commands will print all lines from log.txt that do NOT contain the word 'error'?

    1. grep -i 'error' log.txt
    2. grep -r 'error' log.txt
    3. grep -v 'error' log.txt
    4. grep 'error' log.txt

    Answer: C. grep -v 'error' log.txt

    The -v option in grep is used for inverse matching, which means it will output lines that do not match the given pattern. In this case, it will print all lines from log.txt that do not contain the word 'error'.

  4. What will the cron job entry '0 10 1 * * command' do?

    1. The cron job will run at 10:00 AM on the 1st day of every month.
    2. The cron job will run at 10:00 AM on the 1st day of every hour.
    3. The cron job will run at 10:00 AM on the 1st day of every year.
    4. The cron job will run at 10:00 AM on the 1st day of every week.

    Answer: A. The cron job will run at 10:00 AM on the 1st day of every month.

    In cron syntax, the special time syntax '0 10 1 * *' represents minute (0), hour (10), day of the month (1), month (*), and day of the week (*). This means the cron job will execute at 10:00 AM on the 1st day of every month.

  5. Which of the following best describes how a recursive function works in a realistic project scenario?

    1. The function is called multiple times with the same value of n.
    2. The function is defined inside another function and uses its variables.
    3. The function calls itself with a smaller value of n until it reaches the base case.
    4. The function returns a value and is called by another function.

    Answer: C. The function calls itself with a smaller value of n until it reaches the base case.

    In a recursive function, the function calls itself with a smaller value of n until it reaches the base case. This is the correct description of how recursion works in a realistic project scenario. The other options are either incorrect or describe different concepts, such as iteration or function overloading.

Frequently asked questions

How many questions are in the Intermediate Shell Scripting test?
30 questions (18 multiple choice, 12 multi-answer), with 35 minutes to answer them.
What does the Intermediate Shell Scripting test cover?
Functions, grep, sed and awk, Exit codes and set -e, Arrays, cron.
Is the Intermediate Shell Scripting test free?
Yes. It is free to take with a readyforhires account.
What level is the Intermediate Shell Scripting test?
Intermediate, in DevOps & cloud.

More DevOps & cloud tests

Roles that test these skills

Companies that test these skills

All practice tests · All DevOps & cloud tests

Last updated