readyforhires

Beginner Shell Scripting test (Beginner)

25 questions · 30 minutes · Free

Commands, variables, pipes and simple scripts.

Take the Beginner Shell Scripting test

What it covers

Interview format

Earn a certificate

The Beginner Shell Scripting test is one of the 7 tests of the DevOps Engineer learning path. Pass it and the other 6 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, 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 Beginner 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 does the following command do? 'awk '{sum += $1} END {print sum}' file.txt'

    1. Prints the total number of characters in the file
    2. Counts the number of lines in the file
    3. Prints the sum of the numbers in the first column of the file
    4. Prints the first field of each line in the file

    Answer: C. Prints the sum of the numbers in the first column of the file

    The command 'awk '{sum += $1} END {print sum}' file.txt' adds the values in the first column of the file and prints the sum. The other options are incorrect because they describe different functionalities, such as counting lines or printing individual fields.

  2. What will the command `head -n 5 data.txt` do?

    1. The command will output the last 5 lines of the file 'data.txt'.
    2. The command will output the last 5 characters of the file 'data.txt'.
    3. The command will output the first 5 lines of the file 'data.txt'.
    4. The command will output the first 5 characters of the file 'data.txt'.

    Answer: C. The command will output the first 5 lines of the file 'data.txt'.

    The `head -n 5 data.txt` command is used to display the first 5 lines of the file 'data.txt'. The `-n` option specifies the number of lines to output, and `5` is the number of lines requested. This is a standard usage of the `head` command.

  3. What will happen when the following command is executed: 'read name <<< "Alice"'?

    1. The variable 'name' will contain the value 'Alice' after the read command executes.
    2. The variable 'name' will contain the value 'Alice ' (with a trailing space) after the read command executes.
    3. The read command will fail because the input is not properly formatted.
    4. The variable 'name' will be empty after the read command executes.

    Answer: A. The variable 'name' will contain the value 'Alice' after the read command executes.

    The 'read' command reads a line of input from standard input and assigns it to the variable 'name'. In this case, the input line is 'Alice', so the variable 'name' will contain 'Alice'.

  4. What is the primary purpose of a case statement in shell scripting?

    1. The case statement is used to loop through a list of items.
    2. The case statement is used for performing arithmetic operations.
    3. The case statement allows for pattern matching and executing commands based on the value of a variable.
    4. The case statement is used to redirect output to a file.

    Answer: C. The case statement allows for pattern matching and executing commands based on the value of a variable.

    The case statement is used for pattern matching and executing commands based on the value of a variable. It is particularly useful in scenarios where multiple conditions need to be checked against a single variable. The other options do not accurately describe the functionality of the case statement.

  5. What happens when a variable is interpolated within double quotes in a shell script?

    1. The variable is processed as a command and its output is inserted into the string.
    2. The variable is not expanded and remains as-is in the string.
    3. The variable is expanded recursively, including any nested variables.
    4. The variable value is inserted directly into the string without any processing.

    Answer: D. The variable value is inserted directly into the string without any processing.

    In shell scripting, when a variable is enclosed in double quotes, its value is interpolated into the string. This means that the shell replaces the variable name with its value during execution. However, the value is not subject to further expansion (like command substitution or other variable expansions) unless explicitly specified. This behavior is crucial for controlling how variables are used in strings.

Frequently asked questions

How many questions are in the Beginner Shell Scripting test?
25 questions (15 multiple choice, 10 multi-answer), with 30 minutes to answer them.
What does the Beginner Shell Scripting test cover?
Variables and quoting, Pipes and redirection, Conditionals and loops, Common commands, Script arguments.
Is the Beginner Shell Scripting test free?
Yes. It is free to take with a readyforhires account.
What level is the Beginner Shell Scripting test?
Beginner, 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