Print
Category: Answers
Hits: 1066

LPIC 102-500
Shells and Shell Scripting exam
Answers with explanation

 

  Take the test here (You need an account. It's free)

 

1.    Which of the following best describes the PSI environment variable?
A.    PS1 is used to set the location of the PostScript command.
B.    PS1 is used to define the default shell prompt for bash.
C.    PS1 is used as a per-system variable.
D.    PS1 is user-defined and does not have a default value or setting.

ANSWER: B. The PS1 variable usually has its default set in /etc/profiie and is used as the shell prompt. Users can customize the prompt to include hostname, working directory, and other elements.


2.    Which command is used to read and execute commands from a file in the Bash shell?
A.    run
B.    execute
C.    source
D.    func

 C. The source command is used to execute commands from a file. A typical use case is to create functions or variables that are then available for use within the current session. The other commands listed do not exist.


3.    You need a command to be executed on logout for all users. Within which file should this be placed (assuming all users are using Bash)?
A.    ~/.bash_logout
B.    /etc/bash.bash_logout
C.    /home/.bash_logout
D.    /etc/bash_logout

 B. While it’s true that every user has a . bash_logout in their home directory, that file can still be edited by the user. Therefore, to ensure that the required command is executed at logout, the /etc/bash.bash_logout file must be used.


4.    Which of the following commands removes an environment variable that has been set?
A.    profile -unset
B.    env -u
C.    set -u
D.    import

 B. The env - u command will unset an environment variable for the current session. The unset command can also be used for this purpose.


5.    Which option to the unset command explicitly informs the command that the name given refers to a shell variable and not a function?
A.    -a
B.    -s
C.    -v
D.    -e
 

 C. The -v option, which is the default, tells unset that the name given is a shell variable rather than a function. The other options shown do not exist.


6.    Which of the following commands ensures that the -la options are used when the is command is executed without other options?
A.    alias ls="ls -la"
B.    in -s is is -la
C.    alias "ls -la" = ls
D.    set ls

 A. The alias command is used for this purpose and its format is name=value, making option A correct. The in command cannot be used for this purpose because it will not accept command-line arguments for the target in such a format, as shown in the options.


7.    What is the order in which user configuration files are located on login to a Bash shell?
A.    .bash_login, .profile, /etc/profile
B.    .bash_profile, .bash_login, .profile
C.    .profile, .bash_login, .bash_profile
D.    .bash_login, .bash_profile, .profile

 B. User-based configuration files are located in the order .bash_profile, .bash_login, and .profile. Only the first file found is executed and the others are ignored.


8.    Which variable within a Bash script is used to access the first command-line parameter?
A.    $ARG
B.    $CMD
C.    $1
D.    $ARG0

 C. The $1 variable is automatically available within Bash scripts and represents the first command-line argument. The other variables listed in this question do not exist by default.


9.    Which of the following provides the end for an if conditional in a Bash script?
A.    ex
B.    }
C.    ]
D.    fi

 D. The fi construct is used to indicate the end of an if conditional within a Bash script. In many languages, if conditionals are scoped by braces such as { }, but in shell scripting, fi is used to denote the end of the condition.


10.    Which of the following commands will print a list of 6 numbers beginning at 0 within a Bash script?
A.    list 0-5
B.    seq 0 1 5
C.    echo 0-5
D.    seq 016

 B. The seq command is used to print a sequence of numbers in a variety of formats. The answer for this question provides a starting  point (o), and increment (i), and the final number (5), resulting in six numbers being displayed as output.


11.    When creating a shell script, which of the following commands is used to display the contents of variables?
A.    var_dump
B.    echo
C.    ls
D.    env

 B. The echo command is used to display its argument, regardless of whether the command is used inside a shell script or from the command line itself. The env command is used to display environment variables and therefore does not meet the need specified in the question. The var_dump command is used within PHP, and is is used to display contents of directories.


12.    A command has the following listing obtained with ls -la: -rwsr-xr-x 1 dan dan 21 Nov 2 13:53 script.sh
What does the s denote within the user permissions in the listing?
A.    The suid bit has been set for this program.
B.    This is a symlink.
C.    The file will not be executable.
D.    The file is a special system file.

 A. The suid bit enables the program to run as the user who owns the file regardless of who executes the program. Using SUID is typically not recommended for security reasons.


13.    Which of the following commands will execute a script and then exit the shell?
A.    run
B.    source
C.    ./
D.    exec

 D. The exec command executes the command given as its argument and will then exit the shell. The source command does not exit the shell.


14.    Which sequence of characters will execute two commands but only if the first command exits successfully?
A.    -
B.    &*
C.    &&
D.    &

  C. The double-ampersand sequence executes commands only if the previous command exited cleanly.


15.    Which command within a shell script awaits user input and places that input into a variable?
A.    exec
B.    get
C.    read
D.    prompt

 C. The read command awaits user input and places that input into the specified variable. The exec command is used to execute commands, and the other options are not valid for the purpose described.


16.    What characters are used to mark a sequence of commands as a function in a Bash script?
A.    Parentheses to declare the function (optional) and curly braces to contain the commands
B.    Curly braces to declare the function and parentheses to contain the commands
C.    Square brackets to declare the function and curly braces to contain the commands
D.    Runquotes to denote the function

 A. Parentheses are used to denote a function, such as myFunction(). The parentheses are optional but are then followed by curly braces containing the commands to be executed when the function is called.


17.    Which character sequences denote an alternate command to execute if the preceding command does not exit successfully?
A.    &&
B.    -
C.    ||
D.    EL

 C. The || sequence indicates an alternate command to run if the initial preceding command does not exit cleanly. The && sequence executes only when the preceding command exits cleanly, so it’s just the opposite of what the question was asking.


18.    Which keyword(s) is/are used to begin an alternate condition within a Bash script?
A.    if
B.    else if
C.    elif
D.    elsif

 C. The elif keyword is used to create an alternative execution path within a shell script. The other constructs, such as else if and eisif, are used in other languages.


19.    Which of the following commands removes a currently defined aliased command?
A.    remove
B.    rm
C.    unalias
D.    delete

 C. The unalias command is used to remove a previously defined alias. The rm command will remove regular files but not aliases. The other commands do not exist.


20.    When sourcing a file in Bash, which chmod command would be necessary to provide the minimum privileges in order for the file to be sourced correctly, assuming that your current user owns the file?
A.    chmod 600
B.    chmod 755
C.    chmod 777
D.    chmod 400

 D. At a minimum, you need to be able to read the file being sourced; therefore, chmod 400 will correctly set the permissions. Any chmod that gives additional permissions is not necessary.


21.    Assuming that a space-separated list of values has been defined as LIST="one two three four", which of the following for loop constructs will iterate through the elements in the list?
A.    for LIST
B.    for VAR in LIST
C.    for VAR in $LIST
D.    for $LIST -> $VAR

 C. The for loop construct in this case will require the variable name LIST to be preceded with a dollar sign ($),making option C correct. The other options will not work for the purpose described.


22.    Which test within a shell script while loop will examine one value to see if it is less than another?
A.    -less
B.    -lessThan
C.    -lt
D.    -lthan

 C. The -lt operator is used to test for “less than” conditions within a script. The other operators are not valid for use in a shell script.


23.    Which of the following tests will determine if a file exists in the context of a shell script?
A.    -a
B.    -e
C.    -m
D.    -i

 B. The -e test checks to ensure that a file exists and is typically used in the context of a conditional within a shell script. The other options may work within shell scripts but are not tests for file existence.


24.    Within which directory should you place files to have them automatically copied to a user’s home directory when the user is created?
A.    /etc/userhome
B.    /etc/templateuser
C.    /etc/skel
D.    /home/skel

C. The /etc/skel directory contains files to be copied to the user’s home directory. The other directories listed for this question do not exist by default.
 
25.    Which option to bash will cause the shell to be executed without reading the initialization files?
A.    -no-rc
B.    -no-init
C.    -norc
D.    -rc-none

 C. The -norc option causes bash to execute without reading the /etc/bash.bashrc file or the local ~/.bashrc file. The other options listed do not exist as options for bash.


26.    Which of the following creates an array in a Bash script?
A.    ARRAY=(val1 val2)
B.    ARRAY = "val1 val2"
C.    ARRAY_PUSH($ARRAY,"val1","val2");
D.    ARRAY{0} = "val1"

 A. Array creation in a shell script involves parentheses when used in this manner. You can also use square brackets to define individual elements, as in ARRAY[0] = "val1".


27.    Which option of declare displays output in a way that could then be used as input to another command?
A.    -o
B.    -n
C.    -p
D.    -m

 C. The -p option to declare displays fully qualified shell statements such that the statements could then be used as input for another command, either through piping or redirection to a script.


28.    You need to create a function that will be available each time that you log in to the system. Within which file should this function be placed?
A.    .bash_profile
B.    .rc
C.    /etc/profile
D.    .bash_run

 A. The .bash_profile file, if it exists in your home directory, will be executed on login. Note that placing the function in /etc/profile would technically work but then the function would be available to all users, which is not what the question asked for.


29.    Which shell built-in command is used to display a list of read-only variables?
A.    ro
B.    readonly
C.    env-ro
D.    ro-env

 B. The readonly command displays the list of read-only variables that have been declared in the current session. The other commands listed for this question do not exist.


30.    Which characters are used to denote the beginning and end of the test portion of a while loop in a shell script?
A.    Parentheses ( )
B.    Curly braces { }
C.    Square brackets [ ]
D.    Double-quotes " "

 C. Square brackets are used to denote the beginning and end of the test portion of a whiie loop in a shell script. Other languages generally use parentheses for this purpose.


31.    When using the test built-in with one argument, what will be returned if its argument is not null?
A.    false
B.    true
C.    unknown
D.    -1

 B. The test built-in will return true and can be used to test for the value existence of a variable not being null. Note that the behavior of the test built-in differs depending on the number of arguments.


32.    Which environment variable is used when changing directory with the tilde character, such as cd ~ ?
A.    HOMEDIR
B.    HOMEPATH
C.    HOME
D.    MAILPATH

 C. The HOME environment variable, set automatically to the user’s home directory, is consulted when the command cd ~ is entered.  The other paths beginning with HOME do not exist by default, and the MAILPATH environment variable shown contains a list of locations where mail is checked when using the shell interactively.


33.    Which environment variable can be set if you want to automatically log users out of their shell after a certain period of inactivity?
A.    TIMEOUT
B.    TMOUT
C.    TO
D.    IDLETIME

 B. The TMOUT variable can be set in a given user’s shell and that user will be logged out after the value given (in seconds) of inactivity. The other environment variables listed here do not exist.


34.    When using a case statement within a shell script, which sequence denotes the ending of the case/switch statement?
A.    caseend
B.    esac
C.    endcase
D.    }

 B. Just as with an if statement where the statement is ended with fi, so too is a case statement ended with the word case spelled backward. The curly brace shown as option D is used to close case statements in many languages, but not for shell scripts.


35.    Which of the following commands will obtain the date in seconds since the epoch and place it into a variable called DATE within a shell script?
A.    DATE="$(date +%s)"
B.    DATE="date"
C.    DATE="$(date)";
D.    DATE="$date %s"

 A. The provided answer performs command substitution and places the value from the resulting command into a variable. Note the use of +%s formatting on the date, which then formats the output as seconds since the epoch, as specified in the question. Option C will provide the date within the DATE variable but will not format it as specified.


36.    Assume that you have a variable called $FILEPATH within a Bash shell script. Which characters can be used to ensure that the variable will be interpolated correctly regardless of where the variable appears within the script?
A.    Dollar sign: $FILEPATH
B.    Curly braces: ${FILEPATH}
C.    Parentheses: $(FILEPATH)
D.    Square brackets: $[FILEPATH]

 B. Wrapping a variable in curly braces, such as ${FILEPATH}, will ensure that the variable is interpolated or expanded correctly even when used in a place where it might not normally be expanded, such as within a quoted string.


37.    Which sequence is used to mark the beginning and end of the commands to execute within a for loop in a shell script?
A.    Curly braces: { }
B.    The keywords do and done
C.    Semicolons: ;
D.    Tabs

 B. In shell scripts, the commands to execute begin at the do keyword and end at the done keyword. Other languages generally use either curly braces or tabs.


38.    Which of the following tests will determine if a file exists and can be read by the user executing the test?
A.    -e
B.    -m
C.    -a
D.    -r

 D. The -r test determines whether a given file exists and can be read by the current user. The -e test only checks to see if the file exists.


39.    Which option of the declare command will create a variable that is read-only?
A.    -r
B.    -ro
C.    -p
D.    -x

 A. The -r option to declare will create or mark the variable as read-only. The -p option prints output in a format that can be reused. The -x option declares the variable for export.


40.    Which character sequence is used to provide a default case when used within a case statement in a shell script?
A.    default
B.    = )
C.    —>
D.    *)

 D. The *) sequence is used to denote a default set of statements that will be executed if no other case matches within the set.


41.    Which character sequence can be used for command substitution in Bash?
A.    Backquotes: ' '
B.    Single quotes: ‘ '
C.    Double quotes: ""
D.    Backslashes: \

 A. Backquotes can be used for command substitution within a Bash script. The other options shown are not valid for command substitution.


42.    When using a while loop in Bash, which character sequence marks the end of the loop?
A.    elihw
B.    done
C.    end
D.    od

 B. The character sequence done denotes the end of a while loop in Bash.


43.    Which operator is used to test if a value is greater than or equal to something in a Bash script?
A.    ! =
B.    >=
C.    =>
D.    >>

 B. Greater than or equal to is tested with >=. Of the other operators shown, != tests for inequality.


44.    You are working with a shell script called listusers and the script does not execute with the error "permission denied". What could be the possible cause of this issue?
A.    The script should have an .sh extension.
B.    The script contains a syntax error.
C.    The script does not have its execute permission set correctly.
D.    The script is named with lowercase letters.

 C. The execute bit is not set on the script, resulting in the permission denied error, making option C correct. The file extension does not matter, so option A is incorrect. Likewise, option B is not correct because the script isn’t even executing. Lowercase or uppercase letters do not matter, making option D incorrect.


45.    Which option to the export built-in command makes names available as functions to child processes?
A.    -m
B.    -e
C.    -w
D.    -f

 D. The -f option exports names as functions to child processes. The other options shown do not exist with the export command.


46.    If a variable has been created using the set command, which command can be used to remove the variable?
A.    remove
B.    del
C.    delete
D.    unset

 D. The unset command removes a variable from being set. The other options shown do not exist.


47.    Which of the following files is a systemwide initialization script for Bash?
A.    /etc/bash.bashrc
B.    /etc/bash.init
C.    /etc/bash.cfg
D.    /etc/bash/bash.init

 A. The /etc/bash.bashrc file is a systemwide configuration file for the Bash environment. Another systemwide file used for similar purposes is /etc/profile.


48.    Which option to the set command enables debugging output?
A.    -d
B.    +d
C.    -x
D.    +x

 D. The +x option enables debugging output and is frequently used when debugging shell scripts. The -x option is used to disable debugging. The -d and +d options do not exist.


49.    Which of the following files is executed with every interactive Bash shell invocation?
A.    /etc/bash.d
B.    /etc/bash.interactive
C.    ~/.bash_inter
D.    ~/.bashrc

D. The .bashrc file in a given user’s home directory is executed for interactive logins. The other files shown do not exist.
 
50.    Which keyword declares a block of code to be a function in a Bash script?
A.    function
B.    repeat
C.    func
D.    block

 A. The function keyword declares a block of code to be a function in Bash. It’s worth noting that the function keyword can be omitted in most cases. The other options are not valid.


51.    Which of the following statements adds the /srv/bin path to the path for a Bash shell?
A.    PATH=/srv/bin
B.    PATH=$PATH:/srv/bin
C.    PATH =/srv/bin
D.    PATH=/srv/bin;$PATH

 B. The syntax shown in option B is the correct syntax to add a path to the current environment. Option A does not include the existing path (and will, in fact, overwrite the existing path). Option C contains spaces, and option D uses a semicolon as a delimiter.


52.    Which variable is available to a Bash script and contains the name of the script itself?
A.    $SCR
B.    $SCRIPT
C.    $CMD
D.    $0

 D. The $0 variable is automatically defined and contains the name of the script itself. The other options shown do not exist by default.


53.    Which option to the seq command sets a delimiter of a space between the numbers 1 through 5?
A.    seq -s ' ' 1 5
B.    seq -d ' ' 1 5
C.    seq 1 5
D.    seq -m 1 5

 A. The - s argument enables setting of a delimiter. When used, the numbers will be printed in a sequence rather than one per line. The -m and -d options do not exist.


54.    Which file test is used to determine if you are the owner of the file being tested?
A.    -m
B.    -k
C.    -w
D.    -O

 D. The -O option is used to determine if the user currently running the test is the owner of the file being tested. The -k option checks to see if the sticky bit has been set. There is no -m file test.


55.    When testing a return value in a Bash script, which exit code indicates success?
A.    0
B.    1
C.    2
D.    c

 A. A successful return from a command executed within a Bash script is 0. A 1 or higher typically indicates an error condition. There is no c condition.


56.    You have created a README file and placed it into /etc/skel so that users get the file in their home directories. The file is missing from some home directories on the system. Which of the following best explains this scenario?
A.    The file is not copied automatically for existing users.
B.    The file is too big for a user’s home directory.
C.    The file already exists.
D.    The file needs a file extension.

 A. The file is not copied to directories for existing users, making option A correct. There is nothing in the question to indicate that the file is too big or that it already exists. File extensions don’t matter in Linux, so option D cannot be correct.


57.    You have a Bash script that uses the following find command: find . -name ".git" -type d
When another administrator uses the script, it does not find all of the indicated directories. Which of the following is the best explanation for this scenario?
A.    The find command is tied to specific users.
B.    The find command cannot find directories beginning with a dot.
C.    The find command begins the search in the current directory.
D.    The find command cannot find directories.

 C. The find command begins the search in the current directory, which is problematic in a scripted scenario like the one presented. The find command can find directories, and those directories can begin with a dot character.


58.    You have specialized software that needs to be installed with an empty environment. Which option to the env command can be used to meet this requirement?
A.    -e
B.    -i
C.    -f
D.    -c

 B. The -i option ignores the environment. The other options are not valid for use with env.


59.    Which option enables debugging when used on the interpreter (#!) line within a Bash script?
A.    -x
B.    -d
C.    -a
D.    -f

 A. The -x option enables debugging when passed on the interpreter line of a Bash script. The other options are not valid for this purpose.


60.    Which of the following will output the number 5 as part of a Bash script?
A.    echo 2+3
B.    echo 2+3
C.    echo $[2+3]
D.    echo ${2+3}

 C. Doing math in Bash requires a special syntax. The bc command can also be used for such operations and is frequently used for math within Bash scripts.


61.    You need to prompt the user to enter two values in a Bash script and capture them in variables VALI and VAL2, Which of the following commands can be used for this purpose?
A.    read VAL1 VAL2
B.    prompt VAL1 VAL2
C.    VAL1=$0 VAL2=$1
D.    (VAL1 VAL2) = prompt

 A. The read command will be used, and option A shows the correct syntax. Option C is incorrect because it does not prompt the user. There is no prompt command, making options B and D incorrect.


62.    Which option to the export built-in command removes a variable from being exported?
A.    -m
B.    -o
C.    -r
D.    -n

 D. The -n option removes a variable from being exported. The other options do not exist.


63.    Which of the following tests the return value from the previous command to see if the command was successful?
A.    if [ $? -eq 0 ];
B.    if [ $? = 0 ];
C.    if ($PREV == 0) {
D.    if [ $RETV === 0 ];

 A. The exit code from the previous command is captured automatically in the $? variable, thus ruling out any option that did not have this value. A test for the value is done with -eq in a Bash script, thus making option A correct.


64.    You have a file containing bash functions. Which command can be used to add these functions to the current environment?
A.    function
B.    include
C.    require
D.    source

 D. The source command is frequently used for the purpose described. The function command can be used to create functions but would not be used for the purpose described. The include and require commands are not valid.


65.    Which chmod command grants the user execute permission on a script?
A.    chmod user += exec
B.    chmod u+x
C.    chmod 644
D.    chmod u+all

 B. Adding the execute bit for the user can be done in a non-octal format, as shown in option B. The only other valid chmod option is 644, which does not grant execute permission.


66.    Which find command will locate all files named with an .sh extension?
A.    find / -name "*.sh"
B.    find / -name "*.sh" -type f
C.    find / -name "*.sh" -type d
D.    find ./ -name "*.sh"

 B. The problem statement specified files, making option B the best answer. Option A will also find directories.


67.    Which unset option can be used to remove a function from being defined?
A.    -r
B.    -a
C.    -f
D.    -g

     C. The -f option removes a function. The other options do not  exist for the unset command.


68.    When setting the shebang line of a shell script, which of the following commands will help to determine the location of the interpreter automatically?
A.    #!/usr/bin/env bash
B.    #!/bin/bash
C.    #!env
D.    /bin/int bash

     A. The env command, when used as #! /usr/bin/env bash, will determine the location of the Bash interpreter automatically. This makes the resulting script more portable for systems where Bash may not be located in /bin/.


69.    Which mathematical operator is used for division within a Bash script?
A.    \
B.    /
C.    *
D.    //

 B. The front slash, or forward slash, is used for division. Of the other options, an asterisk is used for multiplication and the other options are not valid.


70.    You need to send an email to the superuser if a command is successful. Which of the following commands will send mail from a Bash script?
A.    smtpsend
B.    mailx
C.    sendm
D.    mailsend

 B. The mailx command can be used to send mail from the command line. The other options shown are not valid commands.


71.    Which file test operator is used to determine if the file is not zero size?
A.    -d
B.    -e
C.    -f
D.    -s

 D. The -s operator tests if a file is not zero size. The -d operator looks for directories, whereas -e merely checks if the file exists.


72.    You have created an alias but it is gone the next time you log in. Which of the following best explains this scenario?
A.    The alias was not placed into an initialization script.
B.    The alias was invalid.
C.    The command is not valid for which the alias was created.
D.    The alias created an invalid symlink.

 A. An alias exists only for the length of the current session, making option A correct. If the alias or command was invalid, you would have seen it immediately when you created or used the alias.


73.    Which of the following is valid syntax to create a variable named FILENAME in a Bash script and set it equal to the second command-line argument?
A.    $FILENAME = $2
B.    FILENAME=1
C.    FILENAME = $(2)
D.    FILENAME=$2

 D. The correct syntax is shown in option D for the scenario described.


74.    You are working with a user who is reporting that their environment does not have certain variables defined, but other users do have those same variables available within their environment on login. The issue was not corrected by having the user log out and then log in again, and you can see their successful login. What is the most likely explanation for this issue?
A.    The user has logged in from the console.
B.    The user is using a different shell.
C.    The user has removed the environment variables manually.
D.    The user is logging in to a different system.

 B. The user is most likely not using Bash but is rather using another shell like Tcsh. The user could be logging into a different system, but hopefully by having them log out and log in again that would have been noticed, as would their manual removal of the environment variables.


75.    Which environment variable contains the username of the currently logged-in user?
A.    LOGNAME
B.    LOGIN
C.    LOGGEDIN
D.    LOGINUSER

 A. The LOGNAME environment variable contains the currently logged-in user. The other variables do not exist by default.


76.    Which file test operator is used to determine if the file is a symbolic link?
A.    -h
B.    -p
C.    -S
D.    -t

 A. The -h test determines if the file is a symbolic link. The - p option tests if the file is a pipe, and -s returns true if the file is a socket. The -t test determines if the file is a terminal.


77.    Which option to the readonly command marks a function as being read-only?
A.    -a
B.    -r
C.    -f
D.    -p

 C. The -f option marks a function as read-only. The -p option prints a list of read-only identifiers. The -a option assumes that the name is an array, and there is no -r option to the readonly command.


78.    Which find command will locate all files where the users have the execute bit set?
A.    find ./ -type f -perm 700
B.    find / -type f -perm -u+x
C.    find / -type f -perm 777
D.    find / -type f -perm -execuser

 B. Option B is the best answer because it will find files where the user permission includes the execute bit. It’s worth noting that options A and C will find the execute bit but only with the exact permissions specified.


79.    According to the FHS, which of the following directories is used for local binaries?
A.    /usr/local/bin
B.    /usr/bin
C.    /usr/sbin
D.    /home/scripts

 A. The /usr/local/bin directory is the location specified for local binaries according to the FHS. It’s also a typical place for scripts  as well. The /usr/bin and /usr/sbin directories are for system binaries, and /home/scripts does not exist by default.


80.    Which key sequence can be used to terminate a Bash script?
A.    Ctrl+d
B.    Ctrl+l
C.    Ctrl+a
D.    Ctrl+c

 D. Ctrl+c is used to terminate a script and is usually used for terminating programs as well.


81.    You need to view the current environment variables in a single line rather than with newlines separating each variable. Which option to the env command can be used for this purpose?
A.    -n
B.    -0
C.    -c
D.    -e

 B. The -0 option follows each environment variable with a null byte rather than a newline. The other options shown are not valid for use with env.


82.    You are attempting to copy several files, but the cp command keeps asking for confirmation before overwriting. Which of the following best describes the most likely cause?
A.    The cp command has been compiled to ask for confirmation.
B.    The cp command always prompts for confirmation.
C.    The cp command cannot be used for the purpose described.
D.    The cp command has been aliased to include the -i option.

 D. In all likelihood, the cp command has been aliased with the -i option. Running unalias cp will correct the issue. It is possible that the cp command has been recompiled to always ask for confirmation, but this is not the most likely cause.


83.    You receive an exit code of 1 when working with the grep command in a Bash script. What does exit code 1 mean with grep?
A.    Error
B.    Success
C.    Search pattern not found
D.    Search pattern found

 C. An exit code of 1 usually means error, but in the case of grep it means that the search pattern was not found.


84.    Which of the file test operators is used to determine if a file is a directory?
A.    -e
B.    -d
C.    -w
D.    -a

 B. The -d test checks if a file is a directory. The -e option checks for existence, and the -a option is no longer used. The -w test checks to see if a file is writable by the current user.


85.    Which of the following statements prepends the /usr/local/bin path to the path for a Bash shell?
A.    $PATH=/usr/local/bin:$PATH
B.    PATH=/usr/local/bin:$PATH
C.    PATH=$PATH:/usr/local/bin
D.    PATH=$PATH;/usr/local/bin

 B. The command shown prepends /usr/local/bin on to the existing path. Option A uses $PATH, which is the incorrect identifier for the left side of the assignment. Option C appends /usr/local/bin rather than prepends, and option D uses a semicolon as a delimiter.


86.    Which looping construct is executed at least once in a Bash script?
A.    while
B.    for
C.    until
D.    case

 C. The until loop construct will execute at least once before the condition is evaluated. The while and for loops both evaluate the condition first. The case statement is not a loop construct.


87.    Which character or character sequence is equivalent to the source built-in in Bash?
A.    <>
B.    .
C.    ->
D.    %

 B. The single dot . can be used as a means to source environment variables. The other characters and character sequences do not work for the purpose described.


88.    Which option to the export built-in command displays the list of exported variables?
A.    -p
B.    -a
C.    -t
D.    -d

A. The -p option displays all exported variables. The other options shown do not exist.

 
89.    Which character or character sequence denotes the beginning of a while loop in a Bash script?
A.    start
B.    {
C.    >>
D.    do

 D. The word do indicates the beginning of a while loop in a Bash script. The other options shown are not valid for the purpose described.