Nos120 Chapter 7 review
Which of the following operators reverses the meaning of a test statement?
!
Which of the following characters can be entered at the beginning of a line in a shell script to ensure that line is recognized as a comment rather than try to execute it?
#
Which of the following variables could access the value "/etc" within the sample shell script, if the sample shell script was executed using the bash sample /var /etc /bin command?
$2
Which of the following represents stderr at the command line when used for redirection?
2
What does &> accomplish when entered on the command line after a command?
It redirects both stderr and stdout to the same location
Consider the following shell script: echo -e "What is your favorite color?--> \c" read REPLY if [ "$REPLY" = "red" -o "$REPLY" = "blue" ] then echo "The answer is red or blue." else echo "The answer is not red nor blue." fi What would be displayed if a user executes this shell script and answers Blue when prompted?
The answer is not red or blue.
The sed and awk commands are filter commands commonly used to format data within a pipe. True or False?
True
Which command can be used to create a new command that will monitor the contents of auth.log as they get added to the file?
alias showauth='tail -f /var/log/auth.log'
Which of the following commands will send the output of the cat command to the grep command to be filtered?
cat /etc/passwd | grep jsmith
Which of the following will display the message welcome home if the cd /home/user1 command is successfully executed? cd /home/user1 && echo "welcome home" cat "welcome home" || cd /home/user1 cd /home/user1 || cat "welcome home" echo "welcome home" && cd /home/user1
cd /home/user1 && echo "welcome home"
Which of the following will look at the /etc/passwd file for any lines containing the word root and display them out to the screen while simultaneously writing the results to a file?
grep root /etc/passwd | tee ~/root.txt
Which of the following commands will display the output of a file while also displaying a line number at the left side of each line for the /etc/passwd file?
nl /etc/passwd
Which construct can be used in a shell script to read stdin and place it in a variable?
read
Which of the following can be included in a shell script to ask the user to type in a password and then store it in the variable named $password?
read -s -p "Please enter the password: " password
Which of the following commands will count the number of lines in a file named data.csv?
wc -l data.csv
Which of the following files can you add filenames to so that the git add * command will not stage them?
.gitignore
Which of the following files is always executed immediately after any user logs in to a Linux system and receives a BASH shell?
/etc/profile
Which of the following would be the results of running the command seq 7?
1 through 7 being displayed one number per line.
Which of the following can be used for comparing values within an if statement? (Choose two.) -neq = -lt -grt
= -lt
Which of the following will take output from a command and append it to the end of a file?
>>
How do you indicate a comment line in a shell script?
Begin the line with #.
Because stderr and stdout represent the results of a command and stdin represents the input required for a command, only stderr and stdout can be redirected to/from a file. True or False?
False
Which of the following will the split command do on a file when no other options are specified?
It will split a file into new equally sized files that are 1/10th of the original file size.
You attempt to perform the git commit -m "Added listdir function" but the command fails. What are possible reasons for the failure? (Choose all that apply.)
No files were added to the Git index beforehand. The user performing the commit has not set their Git user information. The user performing the commit is not running the command from within the Git repo directory.
What would be the effect of using the alias command to make an alias for the date command named cat in honor of your favorite pet?
When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.
You have redirected stderr to a file called Errors. You view the contents of this file afterward and notice that there are six error messages. After repeating the procedure, you notice that there are only two error messages in this file. Why?
You did not append the stderr to the Error file, and, as a result, it was overwritten when the command was run a second time.
Which of the following is the common escape sequence to display a horizontal tab using the echo command?
\t
Which of the following lines can be used to perform command substitution within a shell script? (Choose all that apply.)
`command` $(command)
Levi wants to run 5 commands sequentially, but does not want to create a shell script. He knows that each command is going to take approximately 20 minutes to run individually. However, he would like to go to lunch 15 minutes from now. He knows that he can type all of the commands on the same line and separate them with a certain character to run them sequentially. Which character can he type after each command to have them run one after the next without requiring further input from him?
a semicolon ;
Which of the following commands will display the exit status of the last command used in the BASH shell?
echo $?
The current value for the HOME variable is displayed by which of the following commands? (Choose all that apply.)
echo $HOME echo ~
Before a user-defined variable can be used by processes that run in subshells, that variable must be __________.
exported
Every if construct begins with if and must be terminated with?
fi
Which of the following commands should you use to specify that you want to use Git for version tracking on them?
git add
Which command can be used to download an updated copy of the master branch from the original Git repository?
git pull origin master
Which of the following constructs can be used in a shell script to determine whether two values are equal and if so run another set of commands?
if
The subdirectory newdir does not currently exist in the current directory that you are in. Which of the following commands will create a new directory named newdir and then change into that directory? (Choose two.)
mkdir newdir && cd newdir mkdir newdir; cd newdir
Which command could you use to see a list of all environment and user-defined shell variables as well as their current values?
set
A for construct is a loop construct that processes a specified list of objects. As a result, it is executed as long as there are remaining objects to process. True or False?
true
Both aliases and functions can be used to store commands that can be executed, but functions can also accept positional parameters. True or False?
true
An alias has previously been created named showauth. Which of the following commands can be used to get rid of that alias?
unalias showauth
How many times will the following loop execute as part of a script: #!/bin/bash COUNTER=0 while [ $COUNTER -lt 7 ] do echo "hello world" done
until ctrl-c is used to terminate it (b/c there's no update statement to update counter so this is infinite loop.)