Review 3-2 Linux+ Shell Scripting

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

In the bash shell, the total number of command line arguments is stored in variable: $# $ct $@ $argv# Both A and B

$#

What special built-in shell variable returns all positional parameter values? $# $* $? $$

$*

The first argument on the command line when executing a bash shell script is stored in the variable: $1 @1 $argv[1] A or C is correct.

$1

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 lines can be used to perform command substitution with a shell script? (Choose all that apply.) 'Command' (command) {command] $(command)

'Command' $(command)

Referring to the shell script below, what is the value of $# when the loop terminates? *SCRIPT MISSING* 0 7 1 Undefined

0

Assume the following is entered into a bash shell script: ct=0 ls ~ | while read file do ct=$(($ct+1)) echo $ct. $file done What will be displayed? The count of the number of files in the user's directory. Each entry in the user's home directory. The file permissions of each entry in the user's home directory. All of the above. A and B only.

A and B only.

If the bash shell variable total is equal to 15, which of the following commands displays 3? Echo $(($total / 4)) Echo $(($total%4)) Echo $(($total/5)) All of the above None of the above

All of the above

The purpose of the following line in a bash shell script: #!/bin/bash Is to: Cause the script to be executed as a bash shell script only.. Allow the script to be run as a bash shell script from a tcsh shell. Assures that the bash shell is the one used to interpret the script. All of the above A and B only.

All of the above

In the shell script below, what occurs if no command line argument is entered after the script name? *SCRIPT MISSING* The correct usage message "Usage: addall number-list" Is displayed. The script stops without doing any calculations. There are no numbers to add. All of the above. A and C only.

All of the above.

Referring to the shell script below, what does the shift command do? Shifts through the arguments on the command line. Assigns the values on the command line to $1 in sequence. Causes the value $# to be recalculated. All of the above. B and C only.

All of the above.

What does the following command in .bash_profile (or .profile) do? if [ -f ~/.bashrc ] then . ~/.bashrc Fi Tests whether .bashrc exists in your home directory. If .bashrc is not present in the startup (home) directory, the remaining commands in .bash_profile (.profile) are executed. If .bashrc exists when the login shell runs, the commands in it are executed. All of the above.

All of the above.

Referring to the example shell script below, what would happen if you deleted the shift command? *SCRIPT MISSING* An infinitely executing loop occurs. Both Sum and Count would be equal to 7. The exit status is set to 1. All of the above.

An infinitely executing loop occurs.

Referring to the shell script below, what is the purpose of the exit commands? Provides an exit from the loop. Terminates the shell script. Provide a numeric exit status value. All of the above. B and C only.

B and C only.

How do you create a comment line in a shell script? Begin the line with a "tab" Begin the line with #! Begin the line with a "#" Begin the line with a "@"

Begin the line with a "#"

You can display names and current values of all bash shell environment variables with the following command: Printenv Setenv Env Both A and C are correct. None of the above

Both A and C are correct.

How can you be certain to execute a bash shell in a script? By making the first character in the file a # Enter on the first line of he script the statement: #!/bin/bash Run the script with the command: "/bin/bash scriptname". Both B and C are correct

Both B and C are correct

Given the following bash shell statement: if [[ $# -eq 0 || $# -gt 1 ]] then echo "Usage: $0 ordinary file" exit 1 #(returns an exit value to the shell and is commonly interpreted as a script failure) Fi What condition will cause the echo command to be executed? When $# is 1. If no argument is listed on the command line. If more than one argument is listed on the command line. Both B and C. None of the above.

Both B and C.

Assuming that execute permission for a shell script named: "testscript" has not been set (turned on), then the script: Cannot be executed. Can be executed with the command: /bin/bash testscript Can be executed by adding as the first line in the script #!/bin/bash Can be executed by typing ". testscript"

Can be executed with the command: /bin/bash testscript

Referring to the following shell script, what would happen if a user typed the following command line? *SCRIPT MISSING* Command line: addall 1 4 9 16 25 36 49 Count is equal to 7 Sum is equal to 139 An error occurs after the done statement All of the above.

Count is equal to 7

A keyboard interrupt is: Created by typing CONTROL-C. Generates signal 9. Defaults to the killall command. All of the above. A and B only.

Created by typing CONTROL-C.

What does the following command do? mystery () { who date ls } Executes the function called mystery. Creates a shell script encapsulating who, date, and ls. Creates a function that will execute the commands: who, date, and ls in sequence when called All of the above A and C only.

Creates a function that will execute the commands: who, date, and ls in sequence when called

The command: echo `who | more` Displays output of the who command through the more pipe. Displays the text "who | more" Display the user id and his/her demographic data. None of the above

Displays output of the who command through the more pipe.

What is the result of the following command line? Echo Number of days in 60 years: $((60*365)) Generates an "unexpected token" error message Displays: Number of days in 60 years: 21900 Displays "Number of days in 60 years: $((60*365))" None of these; you must use the let command.

Displays: Number of days in 60 years: 21900

The BASH shell has the ability to execute text files called Linux data commands which contain commands and special constructs. True False

False

The variable: PATH Is made up of a list of directories to be searched in order when commands are executed without an absolute or relative pathname. Changes the location of the PATH variable. Allows the use of a filename as an argument to cd. Allows the use of the list of directories in PATH to be used by the cd command.

Is made up of a list of directories to be searched in order when commands are executed without an absolute or relative pathname.

Given the following statement, in bash Shell script: "demo1": if [ -f "$1" ] then filename = "$1" fileinfo = `ls -il $filename` fi What will be the value of $filename if the following command line is entered? demo1 customers addresses It will be equal to customers. It will be equal to addresses. Its value is undefined because 2 filenames were entered.. Its value is demo1.

It will be equal to customers.

Which construct can be used in a shell script to read stdin and place it in a variable (select multiple)? Read << Input Get

Read

Under bash shell, you can use the following command to read a line from stdin into a variable called word: Read word Set word = 'head 1' @ word < 'head 1' Readline word None of the above

Read word

What is the result of the following Shell command? Read -p "Enter a line of text: " line Outputs the first line of a redirected text file. Reads one line from stdin into variable "line". Resets the variable "line" to the string "Enter a line of text: " Error 101: no variable named "line"

Reads one line from stdin into variable "line"

Given the following block of code in a bash shell script: *CODE MISSING* What value of $option will cause the date to be displayed? d D dD None of the above. Response A and B will work.

Response A and B will work.

Under the bash shell, the command set $(date) is used to: Displays the output of the command: date Sets the variable argv to the output of the date command Set the positional parameters to the output of the date command Both A and C are correct. None of the above

Set the positional parameters to the output of the date command

Consider the following shell script: echo -e "What is your favorite color?--> \c" read REPLY if [ "$REPLY" = "red" -a "$REPLY" = "blue" ] then echo "The answer is red or blue." else echo "The answer is not red nor is it blue." fi The answer is red or blue. The answer is not red nor is it blue There is an error message, because the script has an error in line 1 The answer is red or blue. The answer is not red nor is it blue.

The answer is not red nor is it blue

If the first character on a line in a shell script is a #, the: Script is run under the shell: tcsh The line is treated as a comment The line generates an error message because no valid command is included. Both answers B and C are correct. None of these are correct.

The line is treated as a comment

Assume the following statement occurs first in a bash shell script: if [ $# = 0 ] then directory=~ fi What happens if the shell script is run without an argument? The user's home directory is used. The current working directory is used. The user will be asked to supply a directory. None of the above.

The user's home directory is used.

What is the output of the following script? #!/bin/bash #display_args echo "$1 $2 $3 $4 $5" #end of script "$1 $2 $3 $4 $5" $1.00 $2.00 $3.00 $4.00 $5.00 An error message "too many arguments" The values of the first five command line arguments. None of the above.

The values of the first five command line arguments.

A function is used: To create an encapsulated block of code to be called when needed in a shell script. Must be created in a C program and then compiled. Is legal only in the tcsh shell. None of the above.

To create an encapsulated block of code to be called when needed in a shell script.

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 False

True

How are arithmetic calculations performed in a bash shell command? Using the an expression such as x=$((365*24)) Using the "calc"; for xample calc x=365*24 Using the assignment operator; for example x=364*24 Arithmetic calculations can't be performed in a bash shell command

Using the an expression such as x=$((365*24))

What is the result of the following shell command? name=John Doe II Variable name is created with the value of John Doe II. Variable name is created with value of John. Three variables name, Doe, and II are created. None of the above Both B and C are correct.

Variable name is created with value of John.

Given the following code segment in a bash shell script, while [ "$secretcode" != "$yourguess" ] do echo "Good guess but try again!" read -p "Enter your guess: " done What will cause the loop to continue? When $yourguess is equal to $secretcode. When $secretcode gets a new value. When $secretcode is equal to read secretcode When $yourguess is not equal to $secretcode.

When $yourguess is not equal to $secretcode.

Every if construct begins with if and must be terminated with ___. end endif fi !q

fi

Which of the following commands increments the value of a bash shell variable, sum, by one: Sum = $sum + 1 sum=$(($sum+1)) Sum += 1 $sum++ Both A and B are correct.

sum=$(($sum+1))

What bash command will create variable username and assign it the value of "George W. Bush"? Set username = George W. Bush Setenv username "George W. Bush" @username = George W. Bush username="George W. Bush"

username="George W. Bush"


Kaugnay na mga set ng pag-aaral

Managerial Accounting chapter 21

View Set

PHA 326 Pharmaceutics: Final Exam

View Set

Multi-Digit Long Division Practice

View Set