WGU D281 Linux Foundations - Udemy Section 2- Lesson 6 - Creating Scripts Study pack with, Exams of Business Strategy

WGU D281 Linux Foundations - Udemy Section 2- Lesson 6 - Creating Scripts Study pack with 100% verified answer/solutions- your go to source of Excellence & Success .docx

Typology: Exams

2025/2026

Available from 12/05/2025

studyguru
studyguru 🇺🇸

4.1

(14)

16K documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
WGU D281 Linux Foundations - Udemy Section
2: Lesson 6 - Creating Scripts Study pack with
100% verified answer/solutions- your go to
source of Excellence & Success
99 Q&A
Describe the format of a basic shell script file:
Shell script files must be plain text files; they cannot be generated using a
word processing application. The first line in the shell script should be the
shebang combination (#!/bin/sh). This indicates the shell that should be used
to run the script. The remainder of the shell script is a list of commands or
shell statements arranged in the order in which they are to be run by the shell.
Though not required, it's common to use the exit statement at the end of a
shell script to control the exit status generated by the shell, especially if the
shell exists with any type of error condition.
(MU1_Ch11_ExamEssentials)
Explain how using variables helps when writing a shell script:
Shell Scripts use variables to store data or other information for use later in
the shell script. You assign data to a variable using the equal sign (=). The
data can be any type of text or numerical data, or if you redirect the output of a
command to store in a variable by placing backtick (`) characters around the
command. To reference the value of a variable inside the shell script, precede
the variable with a dollar sign. You can reference variables in shell commands
as well as in shell statements. (MU1_Ch11_ExamEssentials)
Explain how to pass data to a shell script:
Shell scripts can use parameters, or arguments, to pass data from the
command line to shell script. Just include the data parameters on the
command line command when starting the shell script. Inside the shell script
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download WGU D281 Linux Foundations - Udemy Section 2- Lesson 6 - Creating Scripts Study pack with and more Exams Business Strategy in PDF only on Docsity!

WGU D281 Linux Foundations - Udemy Section

2: Lesson 6 - Creating Scripts Study pack with

100% verified answer/solutions- your go to

source of Excellence & Success

99 Q&A

Describe the format of a basic shell script file: Shell script files must be plain text files; they cannot be generated using a word processing application. The first line in the shell script should be the shebang combination (#!/bin/sh). This indicates the shell that should be used to run the script. The remainder of the shell script is a list of commands or shell statements arranged in the order in which they are to be run by the shell. Though not required, it's common to use the exit statement at the end of a shell script to control the exit status generated by the shell, especially if the shell exists with any type of error condition. (MU1_Ch11_ExamEssentials) Explain how using variables helps when writing a shell script: Shell Scripts use variables to store data or other information for use later in the shell script. You assign data to a variable using the equal sign (=). The data can be any type of text or numerical data, or if you redirect the output of a command to store in a variable by placing backtick (`) characters around the command. To reference the value of a variable inside the shell script, precede the variable with a dollar sign. You can reference variables in shell commands as well as in shell statements. (MU1_Ch11_ExamEssentials) Explain how to pass data to a shell script: Shell scripts can use parameters, or arguments, to pass data from the command line to shell script. Just include the data parameters on the command line command when starting the shell script. Inside the shell script

you can retrieve any command line parameters by using positional variables. The $0 positional variable is special; it references the shell command used to launch the shell script. Positional variable $1 references the first parameter entered on the command line, variable $2 the 2nd parameter, and so on. (MU1_Ch11_ExamEssentials) Describe the different types of programming features you can use in shell scripts: Shell scripts can use conditional statements to evaluate data and make programming decisions based on the outcome of the evaluation. The if and case statements are two conditional statements that you can use for that. The if statement can be paired with the else statement to create a true false scenario for executing one set of statements if a condition is true, and another set of statements if a condition is false. The case statement allows you to specify a range of possible values that a condition can evaluate to and execute separate sets of statements for each possible value. Besides conditional statements, shell scripts can use loops to iterate through a set of statements multiple times, based on either a series of values or a condition. Finally, shell scripts can also support defining functions, which are a set of statements bundled together to be called from anywhere in the shell script as needed. (MU1_Ch11_ExamEssentials) After using a text editor to create a shell script, what step should you take before trying to use the script by typing its name? (A) Set one or more executable bits using chmod. (B) Copy the script to the /usr/bin/scripts directory. (C) Compile the script by typing bash scriptname, where scriptname is the script's name. (D) Run a virus checker on the script to be sure it contains no viruses. (E) Run a spell checker on the script to ensure it contains no bugs. Set one or more executable bits using chmod. (MU1_Ch11_ReviewQs)

terminal terminal terminal True or False? False (You've written a simple shell script that does nothing but launch programs. To ensure that the script works with most user shells, the first line should be #!/bin/sh) (MU1_Ch11_ReviewQs) You've written a simple shell script that does nothing but launch programs. To ensure that the script works with most user shells, the first line should be ______________. (A) #!/bin/sh (B) /bin/sh (C) # /bin/sh (D) bash (E) #!bash #!/bin/sh (To ensure that the script works with most user shells, the first line should be #!/bin/sh) (MU1_Ch11_ReviewQs) The ______________ Bash scripting command is used to display prompts for a user in a shell script. (A) case (B) while (C) if (D) echo (E) exit echo (MU1_Ch11_ReviewQs) The ______________ Bash scripting command is used to control the program flow based on a variable that can take many values, such as all the letters of the alphabet. (A) case (B) while

(C) if (D) echo (E) exit case (MU1_Ch11_ReviewQs) The ______________ Bash scripting command controls the return value generated by a script, independent of the other commands used in the script. (A) case (B) while (C) if (D) echo (E) exit exit (MU1_Ch11_ReviewQs) Which one of the following choices is known as the shebang combination? (i) (#/!/bin/sh) (ii) (#!/bin/sh) (iii) (#/bin/sh/!) (iv) (#/bin!/sh) #!/bin/sh (The shebang combination is (#!/bin/sh).) (MU1_KC) Why is scripting considered important in Linux? It saves time by automating repetitive tasks and allows users to focus on more meaningful work. (MU1_USec12_96) What is a Linux script essentially made of? A Linux script is essentially a series of linked commands executed in a specific order. (MU1_USec12_96)

What file can be edited to apply persistent Vim settings like background color? ~/.vimrc (MU1_USec12_97) What abbreviation was created in Vim to insert the shebang line quickly? _abbr _H was created to expand into #!/bin/bash when typed. (MU1_USec12_97) How do you insert a new line in Vim while editing? Press o while in command mode to open a new line below the cursor. (MU1_USec12_97) How do you save and exit a file in Vim? Press Esc, then type :x and press Enter. (MU1_USec12_97) How do you exit a file in Vim without saving changes? Press Esc, then type :q! and press Enter. (MU1_USec12_97) Where should the shebang line be placed in a shell script? The shebang line should always be the very first line of a shell script. (MU1_USec12_97) (MU1_USec12_98) Why is it helpful to add a .sh extension to your script filenames? It helps ensure uniqueness and enables syntax highlighting in editors like Vim or Nano. (MU1_USec12_98) Why should you avoid naming your script the same as existing system commands?

To prevent command name conflicts that could interfere with system behavior or your scripts. (MU1_USec12_98) Where should you place your scripts so they can be run from anywhere without specifying a path? In a directory that is part of your PATH variable, such as a ~/bin directory. (MU1_USec12_98) How do you create a bin directory in your home folder? mkdir bin (MU1_USec12_98) How can you add your ~/bin directory to your PATH variable temporarily? PATH="$PATH:$HOME/bin" (MU1_USec12_98) How do you check if your PATH variable includes your ~/bin directory? echo $PATH (MU1_USec12_98) What command is used to move a script into your ~/bin directory? mv scriptname ~/bin (MU1_USec12_98) What happens if a script is placed in a directory listed in your PATH? It can be run from any location in the file system without specifying the path. (MU1_USec12_98) What is the benefit of using an abbreviation like _sh in Vim? It quickly inserts a shebang line like #!/bin/bash into your script. (MU1_USec12_98) How do you make a script executable only by the owner?

It runs the script in the current shell environment without forking a new process. (MU1_USec12_99) What special variable holds the process ID of the current shell or script? $$ (MU1_USec12_99) How can you demonstrate the difference in process ID when using source vs normal execution? Run the script both ways and echo $$ inside the script; they will differ unless sourced. (MU1_USec12_99) What is the result of echoing $1 inside a script? It prints the first argument passed to the script. (MU1_USec12_99) What happens if no arguments are passed to a script that echoes $1? It prints a blank line or an empty value. (MU1_USec12_99) What happens when you execute ./script.sh Fred and the script contains echo Hello $1? It prints Hello Fred. (MU1_USec12_99) What does $2 represent in a shell script? The second argument passed to the script. (MU1_USec12_99) If a script uses $1 and you pass two arguments to it, which one will be used? Only the first argument will be used unless $2 is also referenced in the script. (MU1_USec12_99)

Why is the source command important for setting variables in your current shell? Because it avoids creating a new subshell and makes variables available immediately in the current shell. (MU1_USec12_99) What happens when a script is run with no arguments and it only echoes $1? It prints just the default message (e.g., "Hello") because $1 is empty. (MU1_USec12_100) What command is used to test if a variable is set in Bash scripts? test -z $ (MU1_USec12_100) What does the command test -z $1 && exit do in a script? It checks if $1 is empty, and if so, exits the script early. (MU1_USec12_100) What is the purpose of using && in test -z $1 && exit? It runs the exit command only if the test command returns true. (MU1_USec12_100) What is a shorthand alternative to the test command in conditional expressions? Using square brackets: [ -z $1 ] (MU1_USec12_100) What is required when using square brackets as a test in Bash? There must be a space after the opening bracket and before the closing bracket. (MU1_USec12_100) What does [ -z $1 ] && exit do? It checks if $1 is empty, and if so, exits the script without printing anything. (MU1_USec12_100)

What command is used to verify that the users were added to the system? tail -n 3 /etc/passwd (MU1_USec12_101) What is the purpose of viewing /etc/passwd with tail -n 3? To see the last three user entries created by the script. (MU1_USec12_101) What is the difference between /etc/passwd and /etc/shadow? /etc/passwd stores user account info, while /etc/shadow stores encrypted passwords. (MU1_USec12_101) Are loops limited to use inside scripts in Bash? No, loops can be typed and executed directly from the command line. (MU1_USec12_101) What other loop types are mentioned besides for loops? while loops and until loops. (MU1_USec12_101) How does a while loop differ from an until loop? While loops execute as long as the condition is true; until loops run until the condition becomes true. (MU1_USec12_101) What is an alternative to the for loop for repeating code in Bash scripts? The while loop. (MU1_USec12_102) Why should variables be quoted in Bash scripts? To prevent errors when the variable contains spaces. (MU1_USec12_102) Why is the '$' not used when assigning input to a variable with read?

Because variable names should not be prefixed with $ on the left-hand side of an assignment. (MU1_USec12_102) What keywords start and end a while loop in Bash? while and done (MU1_USec12_102) What Bash loop runs as long as a condition is false? The until loop. (MU1_USec12_102) What happens if the user presses Enter without inputting a name during the while loop? The loop continues prompting for input. (MU1_USec12_102) What is the purpose of restructuring the Hello script with a while loop? To make the script more functional and user-friendly by handling missing input. (MU1_USec12_102) How does the script behave when a valid name is eventually entered? It echoes the entered name and exits the loop. (MU1_USec12_102) What is the benefit of using a .sh or similar extension when naming scripts? It helps ensure name uniqueness and enables syntax highlighting in editors. (MU1_USec12_104) Where should you create your personal script directory? In your home directory, typically as a bin directory. (MU1_USec12_104) What should you do after creating a script to make it runnable?

It automates repetitive tasks and saves time. (MU1_USec12_104)