linux ch7 comp & rev quiz

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following lines can be used to perform command substitution within a shell script? (Choose all that apply.) `command` ${command} ${!command} $(command)

`command` $(command)

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 ~/.bash_profile ~/.bash_login ~/.profile

/etc/profile

How do you indicate a comment line in a shell script? There are no comment lines in a shell script. Begin the line with #!. Begin the line with !. Begin the line with #.

Begin the line with #.

Which outputs are a result of the following command? (Select two) $ sed s/o/@/g < file1 -R@bin Hood -Blue M@@n -Outstanding Outcome -Oct@ber N@vember

Blue M@@n Oct@ber N@vember

Which line is incorrect for the if construct? A. if [ this is true ] B. then C. do these commands D. elseif [ this is true ] E. then F. do these commands G. fi

D. elseif [ this is true ]

Which outputs are a result of the following command? (Choose all that apply) Assume each original name started with a capitalized letter followed by lower-case letters. $ tr [h-z][H-Z] < names DONaLd DUcK MIcKeY MOUSe WaLT DiSNey WiNNie THe POOH

DONaLd DUcK MIcKeY MOUSe

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

Consider the following shell script:echo -e "What is your favorite color?--> \c"read REPLYif [ $REPLY = "red" -o $REPLY = "blue" ]thenecho "The answer is red or blue."elseecho "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 red or blue. -The answer is not red nor blue. -The code would cause an error. -The answer is red or blue. The answer is not red nor blue.

The answer is not red nor blue.

Which of the following will set VAL to 0? (Choose all that apply) VAL=0 VAL = 0 VAL="0" VAL= "0"

VAL=0 VAL="0"

Find the match. stderr() stdout() stdin() | 0 2 1 Redirection Pipe 3

stderr() 2 stdout() 1 stdin() 0 | Pipe

Which commands will work? (Select two) -$ ls > file1 -$ file1 > file2 -$ wc < file1 -$ wc | file1

$ ls > file1 $ wc < file1

How do you run a shell script? (Select three) Assume the file has the execute bit set . PATH is not set to the current directory. myscript.sh ./myscript.sh . ./myscript.sh source ./myscript.sh

./myscript.sh . ./myscript.sh source ./myscript.sh

What does &> accomplish when entered on the command line after a command? -It redirects both stderr and stdout to the same location. -It does not accomplish anything. -It redirects both stderr and stdin to the same location. -It appends stdout to a file.

It redirects both stderr and stdout to the same location.

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 or False

True

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? -It cannot be done as there already is an environment variable cat associated with the cat command. -It cannot be done because there already is a command cat on the system. -When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead. -There is no effect until the alias is imported because it is a user-declared variable.

When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.

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/user

cd /home/user1 && echo "welcome home"

Before a user-defined variable can be used by processes that run in subshells, that variable must be __________. -imported -Falsevalidated by running the env command -exported -redirected to the BASH shell

exported

Which construct can be used in a shell script to read stdin and place it in a variable? read sum verify test

read

Which of the following operators reverses the meaning of a test statement? #! o a !

!

Which command will display the following information? The number of users who use BASH shell -$ cat /etc/passwd | cut -d: -f7 | sort | grep bash -$ cat /etc/passwd | cut -d: -f7 | sort | wc -l -$ cat /etc/passwd | cut -d: -f7 | wc -l | grep bash -$ cat /etc/passwd | cut -d: -f7 | grep bash | wc -l

$ cat /etc/passwd | cut -d: -f7 | grep bash | wc -l

Suppose file1 exists but dir1 does not. Which commands will write stdout and stderr to separate files? (Select two) $ cat file1 dir1 >file2 2>file3 $ cat file1 dir1 >file2 >file3 $ cat file1 dir1 >>file2 >>file3 $ cat file dir1 2>file3 1>file2

$ cat file1 dir1 >file2 2>file3 $ cat file dir1 2>file3 1>file2

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? $0 $1 $2 $3

$2

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.) -The user performing the commit has not set their Git user information. -No files were added to the Git index beforehand. -The user performing the commit is not running the command from within the Git repo directory. -The master branch was not specified within the command itself.

-The user performing the commit has not set their Git user information. -No files were added to the Git index beforehand. -The user performing the commit is not running the command from within the Git repo directory.

What will be displayed? Assume the script has the execution bit set. $ cat myscript.sh #! /bin/bash echo "$0 $@ $1 $2" #./myscript.sh Hello World! Nothing Hello World! ./myscript.sh Hello World! ./myscript.sh Hello World! Hello World!

./myscript.sh Hello World! Hello World!

The current value for the HOME variable is displayed by which of the following commands? (Choose all that apply.) echo HOME= echo ~ echo $HOME echo ls HOME

echo ~ echo $HOME

Every if construct begins with if and must be terminated with? -end -endif -stop -fi

fi

Which command could you use to see a list of all environment and user-defined shell variables as well as their current values? ls /var env set echo

set

The sed and awk commands are filter commands commonly used to format data within a pipe. True or False? True or False

True

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? -After you open the file and view the contents, the contents are lost. -The system generated different stdout. -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. -You must specify a new file each time you redirect as the system creates the specified file by default.

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.


Conjuntos de estudio relacionados

Statistics - mean, median, mode, range, data types

View Set

Chapter 34: Coronary Artery Disease and Acute Coronary Syndrome

View Set

2ND TRIMESTER ARRT - Incorrectly answered questions

View Set

History of Journalism, Laws, and Ethics

View Set

250 Foundations Comprehensive Final

View Set