Unix Ch 7

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

True

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?

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

A function is used:

Error messages generated by the command, if any

After executing the following command: ls /etc/hosts /etc/h 2>badoutput What will be the contents of badoutput?

a & b only

Assume the following is entered into a bash shell script: ct=0ls ~ | while read filedoct=$(($ct+1))echo $ct. $filedoneWhat will be displayed?

The user's home directory is used.

Assume the following statement occurs first in a bash shell script:if [ $# = 0 ]then directory="~"fiWhat happens if the shell script is run without an argument?

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

Assuming that execute permission for a shell script named: "testscript" has not been set (turned on), then the script:

Bourne Again Shell

BASH is an acronym for:

False

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.

exported

Before a user-defined variable can be used by processes that run in subshells, that variable must be ____________.

True

Both aliases and functions can be used to store commands that can be executed, but functions also accept positional parameters.

The answer is not red nor is it blue

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

fi

Every if construct begins with if and must be terminated with ___.

stdin, stdout, stderr

For each command that can be manipulated by the BASH shell, which of the following are valid file descriptors?

both b & c

Given the following bash shell statement: if [[ $# -eq 0 || $# -gt 1 ]]thenecho "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?

Response A or B will work

Given the following block of code in a bash shell script: #EXAMPLE C option = $1 case "$option" d|D) date ;; l|L) ls ;;w|W) who ;;q|Q) exit 0 ;;esacWhat value of $option will cause the date to be displayed?

When $yourguess is not equal to $secretcode.

Given the following code segment in a bash shell script,while [ "$secretcode" != "$yourguess" ] doecho "Good guess but try again!"read -p "Enter your guess: "doneWhat will cause the loop to continue?

It will be equal to customers

Given the following statement, in bash Shell script: "demo1": if [ -f "$1" ] thenfilename = "$1" fileinfo = `ls -il $filename` fi What will be the value of $filename if the following command line is entered? demo1 customers addresses

count is equal to 7

Given the following statement, in bash Shell script: "demo1": if [ -f "$1" ] thenfilename = "$1" fileinfo = `ls -il $filename` fi What will be the value of $filename if the following command line is entered? demo1 customers addresses

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

How are arithmetic calculations performed in a bash shell command?

B & C are correct

How can you be certain to execute a bash shell in a script?

double quotations permit variable and parameter expansion while single quotations suppress all expansions.

How do double quotation marks (") differ from single quotation marks (') affect expansion on the command line?

all the above

If the bash shell variable total is equal to 15, which of the following commands displays 3?

the line is treated as a comment

If the first character on a line in a shell script is a #, the:

You will get an error message of "command not found"..

If your search path does not include the path to a particular shell file, and you try to run that shell file by typing its name on the command line, what happens?

$#

In the bash shell, the total number of command line arguments is stored in variable:

all the above

In the shell script below, what occurs if no command line argument is entered after the script name? #!/usr/bin/bash# EXAMPLE shell script# Filename addall# Purpose: To demonstrate use of numeric calculations # Brief Description: Maintain running sum of numbers in a numeric # variable called sum, starting with 0. Read # the next integer and add it to sum. When all # elements have been read, stop and display the # answer. # If run with no arguments, inform the user of command syntax if [ $# = 0 ] then echo .Usage: $0 number-list. exit 1 fi sum=0 # Running sum initialized to 0 count=0 # Count the count of numbers passed as arguments while [ $# != 0 ] do sum=$((sum+$1)) # Add the next number to the running sum count=$((count+1)) # Update count of numbers added so far shift # Shift the counted number out done # Display final sum echo .The sum of the given $count numbers is $sum.. exit 0

$$

Inside a bash shell script, you can access the PID of the script using which of the following environment variables:

An infinitely executing loop occurs.

Referring to the example shell script below, what would happen if you deleted the shift command? #!/usr/bin/bash# EXAMPLE shell script# Filename addall# Purpose: To demonstrate use of numeric calculations # Brief Description: Maintain running sum of numbers in a numeric # variable called sum, starting with 0. Read # the next integer and add it to sum. When all # elements have been read, stop and display the # answer. # If run with no arguments, inform the user of command syntax if [ $# = 0 ] then echo .Usage: $0 number-list. exit 1 fi sum=0 # Running sum initialized to 0 count=0 # Count the count of numbers passed as arguments while [ $# != 0 ] do sum=$((sum+$1)) # Add the next number to the running sum count=$((count+1)) # Update count of numbers added so far shift # Shift the counted number out done # Display final sum echo .The sum of the given $count numbers is $sum.. exit 0

all the above

Referring to the shell script below, what does the shift command do? #!/usr/bin/bash# EXAMPLE shell script# Filename addall# Purpose: To demonstrate use of numeric calculations # Brief Description: Maintain running sum of numbers in a numeric # variable called sum, starting with 0. Read # the next integer and add it to sum. When all # elements have been read, stop and display the # answer. # If run with no arguments, inform the user of command syntax if [ $# = 0 ] then echo .Usage: $0 number-list. exit 1 fi sum=0 # Running sum initialized to 0 count=0 # Count the count of numbers passed as arguments while [ $# != 0 ] do sum=$((sum+$1)) # Add the next number to the running sum count=$((count+1)) # Update count of numbers added so far shift # Shift the counted number out done # Display final sum echo .The sum of the given $count numbers is $sum.. exit 0

script terminates & provides a numeric exit value

Referring to the shell script below, what is the purpose of the exit commands? #!/usr/bin/bash# EXAMPLE shell script# Filename addall# Purpose: To demonstrate use of numeric calculations # Brief Description: Maintain running sum of numbers in a numeric # variable called sum, starting with 0. Read # the next integer and add it to sum. When all # elements have been read, stop and display the # answer. # If run with no arguments, inform the user of command syntax if [ $# = 0 ] then echo .Usage: $0 number-list. exit 1 fi sum=0 # Running sum initialized to 0 count=0 # Count the count of numbers passed as arguments while [ $# != 0 ] do sum=$((sum+$1)) # Add the next number to the running sum count=$((count+1)) # Update count of numbers added so far shift # Shift the counted number out done # Display final sum echo .The sum of the given $count numbers is $sum.. exit 0

0

Referring to the shell script below, what is the value of $# when the loop terminates? #!/usr/bin/bash# EXAMPLE shell script# Filename addall# Purpose: To demonstrate use of numeric calculations # Brief Description: Maintain running sum of numbers in a numeric # variable called sum, starting with 0. Read # the next integer and add it to sum. When all # elements have been read, stop and display the # answer. # If run with no arguments, inform the user of command syntax if [ $# = 0 ] then echo .Usage: $0 number-list. exit 1 fi sum=0 # Running sum initialized to 0 count=0 # Count the count of numbers passed as arguments while [ $# != 0 ] do sum=$((sum+$1)) # Add the next number to the running sum count=$((count+1)) # Update count of numbers added so far shift # Shift the counted number out done # Display final sum echo .The sum of the given $count numbers is $sum.. exit 0

False (not called data commands)

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

Displays output of the who command through the more pipe.

The command: echo `who | more`

$person is displayed

The command: echo \$person

will display the string $person

The command: echo \$person

echo $HOME

The current value for the HOME variable is displayed by which of the following commands?

a file name entered at the shell prompt is not executable

The error message: "permission denied" occurs when:

$1

The first argument on the command line when executing a bash shell script is stored in the variable:

the search path

The list of directories stored in the PATH variable is known as

Bash, Tcsh/Csh, Ksh, and Zsh, C shells

The names of the common shell programs in Linux are:

all the above

The purpose of the following line in a bash shell script: #!/bin/bash is to:

True

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

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

The variable: PATH

Creates a user-defined variables city and initializes it to Los, and tries to execute Angeles as a command.

Under Bash Shell, the command: city=Los Angeles

"current date" followed by output of the date command using command substitution

Under Bash Shell, the command: echo The current date is `date` creates:

displays the message "The current date" followed by output of the date command.

Under Bash Shell, the command: echo The current date is `date` creates:

Makes a copy of the current value of the shell variable place available to the commands/scripts executed under the shell

Under Bash shell, the command: export place=Austin

all the above

Under Bash shell, the command: export CDPATH=$HOME:$HOME/MyFiles causes:

A list of directory paths to be searched to locate an external command

Under Bash shell, the environment variable PATH contains the absolute pathnames of:

All of the above

Under Bash shell, the following command creates a user-defined shell variable, called name, and initializes it to John Doe:

read word

Under bash shell, you can use the following command to read a line from stdin into a variable called word:

all the above

Under the Bash Shell the command: cat myaliases > ronsaka 2> errors will

Set the positional parameters to the output of the date command

Under the bash shell, the command set $(date) is used to:

use of the readonly command

Variables "name" and "place" can be made constant by:

username="George W. Bush"

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

unset name

What command removes the variable "name" that has been created in a shell?

alias dir='ls -al'

What command will create an alias name dir which will execute the "ls -al" command?

It redirects both stderr and stdout to the same location

What does &> accomplish when entered on the command line after a command?

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

What does the following command do? mystery () { who date ls }

all the above

What does the following command in .bash_profile (or .profile) do? if [ -f ~/.bashrc ] then . ~/.bashrc fi

all the above

What is the character used to separate elements on the Linux command line?

all the above

What is the difference between a shell function and a shell script?

No difference

What is the difference in output between these two command: echo The working directory is `pwd` echo The working directory is $(pwd)

the values of the first five command line arguments

What is the output of the following script? #!/bin/bash #display_args echo "$1 $2 $3 $4 $5" #end of script

reads one one line from stdin into variable "line".

What is the result of the following Shell command? read -p "Enter a line of text: " line

variable name is created with value of John.

What is the result of the following Shell command?name = John Doe II

displays: Number of days in 60 years: 21900

What is the result of the following command line? echo Number of days in 60 years: $((60*365))

PWD

What shell environmental variable is set equal to the path of the current working directory?

*

What special character represents 0 or more characters on the Bash shell command line?

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

What would be the effect of using the alias command to make an alias for the date command named "cat" in honor or your favorite pet?

a valid LInux command name

When interpreting your commands, the shell assumes the first word you type on the command line is

echo

Which command can be used to display the value of a specific variable?

set

Which command could you use to see a list of all environment and user-defined shell variables as well as their current values.

read

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

sum=$(($sum+1))

Which of the following commands increments the value of a bash shell variable, sum, by one:

The token |& is shorthand for 2>&! and either will send output redirected through a pipe to another command

Which of the following commands will declare file descripter 2 (stderr) to be a dupblicate of file descripter 1 (stdout) and sends both to the tr command?

cat myfile names |& tr "[a-z]" "[A-Z]"

Which of the following commands will declare file descripter 2 (stderr) to be a dupblicate of file descripter 1 (stdout) and sends both to the tr command?

/etc/profile

Which of the following files is always executed immediately after any user logs in to a Linux system and receives a BASH shell?

'command' and $(command)

Which of the following lines can be used to perform command substitution with a shell script? (Choose all that apply.)

!

Which of the following operators reverses he meaning of a test statement?

$2

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?

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

Which of the following will display the message "welcome home" if the cd /home/user1 command is successfully executed?

$*

Which special built-in shell variable returns all positional parameter values?

both A & C are correct

You can display names and current values of all bash shell environment variables with the following command:

created by typing CONTROL- C.

a keyboard interrupt is


Kaugnay na mga set ng pag-aaral

Sensory perception practice questions

View Set

Small Animal Surgical Nursing Ch 2

View Set

Chapter 14: Shock and Multiple Organ Dysfunction Syndrome

View Set

chapter 2 Concepts of Health, Illness, Stress, and Health Promotion

View Set

Ch 13: Personal Selling and Sales Promotion DSM

View Set