Class-Linux223-Q8

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

How many elif statements can be associated with an if statement?

As many as you wish

True or False. The code in the body of the for loop can only be used for counting. You can NOT do any other calculations in this code.

False

What is the best way to detect and prevent code that may loop infinitely?

Start with the sample code from a script for this class, or find sample code on the Internet

What bc command would you use to see 4 places of precision after the decimal?

scale=4

What difference, if any, is there between a "while" loop and an "until" loop?

"while" loops repeat as long as the test is true, versus "until" loops that repeat as long as the test is false.

When should you use a "while" loop (or conditional loop) instead of a "for" loop (or counting loop)?

"while" loops should be used when you do not know how many times the loop code should be executed.

Assume you want to check if the variable $total is greater than or equal to 50. Which of the following would you use?

$total -ge 50

True or False. You can NOT combine a "for" loop and a "while" loop in the same shell script.

False

Assume I want to assign the value green to a variable named color. Is there anything wrong with the following statement? color = green

Yes, there is a problem. There must be no space characters on either side of the equal sign.

What command would you use to display the value of the color variable?

echo $color

Assume you want bc to evaluate 7-2*4, but you want the subtraction to occur first. What would the correct syntax be?

echo '(7-2)*4' | bc

Which of the following would print a "$" character, followed by the value stored in the variable named discount?

echo -e "\$$discount"

Assume that you prompt the user for a starting loop value using the following code: echo -n "Enter loop starting value: " read loopStart junk Which of the following would you use to create a loop that uses the value entered by the user, then counts up to 100 by ones?

for (k=$loopStart; k<=100; k=k+1)

What should the first line in any bash shell script be?

#!/bin/sh

What is the name of the variable that holds the current process number?

$$

What is the name of the variable that holds the name of the currently running shell script?

$0

In the Bourne shell (sh), what option does the echo command need to expand \t to a tab and \n to a newline?

-e

Which option or argument is with the echo command to instruct it to keep the cursor at the end of the current line instead of dropping down to the next line?

-n

What is a shell script?

A program written using the same commands, redirects, pipes etc. that we use in the command line.

What do you call art which is created using multiple lines of text characters?

ASCII Art

Which of the following is NOT a requirement for writing a "while" loop (conditional loop)?

Ensuring that the loop counts up (increments) and not down (decrements)

True or False - In a shell script comments must start at the beginning of a line and must be the only thing on the line.

False

True or False. To pass this class you must be able to write complicated shell scripts.

False

Are there any differences in the way double quotes and single quotes protect things between the csh/tcsh shells and the the sh/bash shells?

No. In both shells single quotes protect filename wildcards and variables, while double quotes protect filename wildcards.

What happens if your code causes an infinite loop?

The loop code runs forever unless the user kills the program or the computer is shut down.

How many times would the code in a loop controlled by the following statement execute? repeat for filename in *.htm

The shell will build a list of all files in the current directory that match *.htm. The code will loop once for each of these files.

True or False. It's possible to write a "while" loop that repeats as many times as a user wishes. That is, it will continue to run until the user says to stop.

True

Assume you want to write an if statement and test to see if the variable $total is equal to 25. What, if anything, is wrong with the test [$total -eq 25] ?

You need spaces before and after the square brackets. It should be [ $total -eq 25 ]

Which of the following would multiply 192*4238 and store the result in the variable bigNum?

bigNum=echo′192⋅4238′∣bc

Which of the following is the correct syntax for using the bc command to calculate 673/19?

echo '673/19' | bc

Which of the following would you use in a shell script to have bc calculate the square root of 121?

echo 'sqrt(121)' |bc

What is the correct command for building a loop which will repeat 5 times?

for ((i=1; i<=5; i++))

Which of the following loops would start at 200 and count down to 100, subtracting 4 each time the code in the body of the loop completed?

for (n=200; n>=100; n=n-4)

What command is used to read user input into a variable?

read


Ensembles d'études connexes

Brendan Major physical science chapter 21 section 21.1 page 630

View Set

Chapter 9 - Production and operations management

View Set

Reading 24: Non-current Liabilities

View Set

Chapter 16: Schizophrenia (Prep U)

View Set

Nutrition Exam #2: Chapter 6 Protein

View Set

Management of Patients with Neurologic Dysfunction (Chapter 66)

View Set