Working with the Bash Shell (questions)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

!

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

$ 2

Which of the following is used for combining two outputs? > | & #

&

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)

You need to make the shell script executable. Which of the parameter along with the chmod command should you use? -x -rwx +x +rwx

+x

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.

- 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 user performing the commit has not set their Git user information.

Which of the following can be used for comparing values within an if statement? (Choose two.) -lt -neq = -grt

-lt =

Which of the following file is executed when a login shell exits? .profile /etc/hosts ~/bashrc .bash_logout

.bash_logout

Which of the following files can you add filenames to so that the git add * command will not stage them? .gitignore .gitnopush .ignore .nopush

.gitignore

Which of the following is activated when the user logs on and also loads the environment variables? /etc/hosts ~/bashrc /var/passwd .profile

.profile

What is the extension of a shell script?

.sh

The _________ gets executed only during a login shell.

/.bash_profile

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

Which of the following is the global profile used for all the users in a Linux system? /etc/users /etc/bash /etc/hosts /etc/profile

/etc/profile

Which of the following standard input value is used for the default keyboard?

0

Which two standard output values are used for the default terminal? [Choose two.] 3 2 0 1 4

1 2

Which value with the chmod command will make a shell script executable? 444 700 400 100

700

The output of a command is redirected to a new file with the help of the _____ operator.

>

To send the content of one file to another file, you can use the _______ redirector.

>

Which operator will overwrite the contents of an existing file? << < > >>

>

To append the information to an existing file, which type of redirector should be used?

>>

Which of the following will take output from a command and append it to the end of a file? < << > >>

>>

Which operator will append the output to the same file without overwriting it?

>>

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 #.

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

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 stderr and stdin to the same location. It appends stdout to a file.

It redirects both stderr and stdout to the same location.

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 files that are 1 kilobyte each. - It will split a file into new files that are 1 megabyte each. - It will split a file into new equally sized files that are 1/10th of the original file size. - It will split a file into new files that are 1,000 lines each.

It will split a file into new equally sized files that are 1/10th of the original file size.

The default output of a command is displayed on the _______. [Choose all that apply.] File Screen Console Keyboard

Screen Console

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

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

True

Which variables are contained in /etc/profile? [Choose all that apply.] USER MAIL HOSTNAME PATH HISTSIZE

USER MAIL HOSTNAME PATH HISTSIZE

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 because 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.

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 because 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.

Which are two methods to execute a shell script named plab.sh? [Choose two.] plab.sh ./plab.sh .plab.sh bash plab.sh

bash plab.sh ./plab.sh

Which of the following results would be created by the command sequence: echo 'apple banana carrot dog elephant' | while read a b c; do echo result: $c $b $a; done - elephant dog carrot - apple banana carrot dog elephant - carrot dog elephant banana apple - carrot dog elephant apple banana

carrot dog elephant banana apple

In a scenario, where you have multiple conditions, it is best to use ________ statements.

case...esac

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"

The ________ command is another filter that is used to print the selected output of a file onto the screen.

cut

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

Which command prints the all exported environment variables? env set print printenv

env

Which command will list the environment variables? nice top ps env renice

env

The _______ command is another filter that converts tabs to spaces, without affection the source file. By default, a tab consists of eight spaces.

expand

Which command enables you to export variables to be used by other processes? env nice top ps renice export

export

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

exported

Every if construct begins with if and must be terminated with _____ . end endif stop fi

fi

The _______ command is used to define the uniform spacing between words and sentences.

fmt

The ______ loop runs through a list of values in a list until the time list values are exhausted.

for loop

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? (Choose two.) - cat /etc/passwd | grep root | merge ~/root.txt - cat /etc/passwd | grep root >> ~/root.txt - grep root /etc/passwd | tee ~/root.txt - grep root /etc/passwd | split ~/root.txt

grep root /etc/passwd | tee ~/root.txt

You can use the ______ loop to check for a condition and perform a task.

if

The _______ statements are mainly used for making a decision and therefore, are known as decision-making statements.

if...else

Which command prints partial or full environment variables? env print printenv set

printenv

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

read

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

Which command prints the name and value of each shell variable available? print env set printenv

set

You can use ________ to convert the spaces back to default tabs in a file.

unexpand

Which of the following commands will count the number of lines in a file named data.csv? lc data.csv wc -l data.csv lines data.csv count -l data.csv

wc -l data.csv

Which of the following executes a list of commands repeatedly till the specified condition is reached? while if for do

while

Which two loops run until a statement becomes true? [Choose two.] while loop if...else for loop case...esac until loop

while loop until loop

Which command should you enter to save and exit a file that is opened in the vi editor?

wq

Which operator is typically used with the xargs command? > | & #

|

If the ~/.bash_profile does not exist, then the __________ file is read.

~/.bash_login

The ____ profile is the user configuration file in which the user environment can be configured.

~/.bash_profile


Ensembles d'études connexes

Medical Terminology, Chapter 10: Musculoskeletal (Anatomy & Physiology)

View Set

4.4) Sleep Problems and Disorders

View Set

Chapter 8: "Why do Financial Crises Occur and Why Are They So Damaging to the Economy"

View Set