IT244 Final (Second Half)

studied byStudied by 0 people
0.0(0)
get a hint
hint

What does the ? meta-character match?

1 / 99

100 Terms

1

What does the ? meta-character match?

Any single character

New cards
2

What does the * meta-character match?

Zero or more occurrences of any character

New cards
3

What do the [ ] meta-characters match?

A single instance of any character between the brackets

New cards
4

What command would you use to see all files in your current directory whose name began with "foo", followed by another letter, followed by “txt”?

ls foo?.txt

New cards
5

What do you call a command whose code is part of the shell and does not exist as an executable file on disc?

A built-in

New cards
6

Name the three ways a shell can be started.

login shell, interactive non-login shell, non-interactive shell

New cards
7

What is the name of the startup file that we will be using in this course which contains commands that are run when you first log in?

.bash_profile

New cards
8

Where are the startup files located?

In your home directory

New cards
9

What command would you use the find out more about a built-in command?

help

New cards
10

Are the commands in .bash_profile run when you create a subshell using bash?

No

New cards
11

What is the value of the file descriptor for Standard Input?

0

New cards
12

What is the value of the file descriptor for Standard Output?

1

New cards
13

What is the value of the file descriptor for Standard Error?

2

New cards
14

If you wanted to run the executable file backup in your current directory but wanted the error messages to disappear, what would you write at the command line?

./backup  2>  /dev/null

New cards
15

If you wanted to run the executable file backup in your current directory but wanted both the output and the error messages to go to the file results.txt, what would you write at the command line?

./backup  &>  results.txt

New cards
16

What would you type at the command line if you wanted to make the script cheer.sh executable?

chmod 755 cheer.sh

New cards
17

Write the hashbang line we use for scripts in this course.

#! /bin/bash

New cards
18

Write the hashbang line you would use if you wanted a script to run using the sh shell.

#! /bin/sh

New cards
19

Name the three categories of people who might need to read a shell script.

The person who wrote the script, the persons who use the script, and the person who maintains the script

New cards
20

What command would you use to make the changes you made in the startup file for your login shell take effect?

source .bash_profile

New cards
21

What is special about a global variable?

You can use it in any subshell of the shell in which it was created.

New cards
22

What are the limitations of a local variable?

You can only use it in the shell in which it was created

New cards
23

What would you write on the command line to set the value of the local variable named team to Red Sox.

team="Red Sox"

New cards
24

If you define a local variable, can a script see the value of this variable?

No

New cards
25

What would you write on the command line to create the global variable named school to UMass Boston.

export school="UMass Boston"

New cards
26

Write the command you would use in a script to ask the user to provide a value for a variable named dir.

read -p "Directory: " dir

New cards
27

What command would you use to see all global variables?

env

New cards
28

What character would you use if you wanted to run two commands in the foreground, one right after the other, on a single command line?

;

New cards
29

What other two characters allow more than one command to be run on a single command line?

& and |

New cards
30

How can you continue a command onto the next line?

type \ immediately before hitting Enter

New cards
31

What parameter gives the status code returned by the last command run?

?

New cards
32

What parameter gives the total number of arguments passed to a script from the command line?

#

New cards
33

What parameter gives the full pathname of the script that is currently being run?

0

New cards
34

What parameter gives the first command line argument to a script or function?

1

New cards
35

If you wanted to use the value of the variable team inside quotes, what kind of quotes would you use?

Double quotes

New cards
36

If you wanted to remove the value of the variable team, what would you type at the command line?

team = or unset team

New cards
37

What is the name of the first process created when the machine starts?

init or systemd

New cards
38

Can two processes running at the same time have the same process ID number?

No

New cards
39

Can a process ID number be reused after the process has finished?

Yes

New cards
40

If the process ID of your current shell is 15062, what is the parent process ID of a shell script you run from your current shell?

15062

New cards
41

What command would you run to see the last 20 commands you ran at the command line?

history 20

New cards
42

What is the pathname of the file that, by default, stores the commands you have run in a file so that they will be remembered for the next time you log in?

~/.bash_history

New cards
43

What command would you use to edit the last command to run, change it and run it again?

fc

New cards
44

What is the name of the library of procedures that allows you to edit the command line?

The Readline library

New cards
45

Name the three things that can be completed at the command line by hitting Tab.

pathnames, commands, shell variables

New cards
46

What do you call a shortcut that is used to run a command?

an alias

New cards
47

What would you write at the command line to create the alias ghdir which changed directory to my home directory?

alias ghdir='cd ~ghoffman'

New cards
48

Can you write a function on a single command line?

Yes if every command is followed by a ; including the last

New cards
49

Can aliases be made global?

No

New cards
50

Can functions be made global?

No

New cards
51

What does Bash do when it performs history expansion?

It reruns an old command line which it retrieves from the history list

New cards
52

What does Bash do when it performs alias substitution?

It replaces the name of the alias with a Unix command

New cards
53

Write the command you would use to create the files foo1.txt to foo5.txt using brace expansion and the touch command.

touch foo{1,2,3,4,5}.txt

New cards
54

What does Bash do when it performs tilde (~) expansion?

Replaces ~ with the absolute address of your home directory or replaces ~UNIX_USERNAME with the absolute address of the home directory of UNIX_USERNAME

New cards
55

What does Bash do when it performs parameter and variable expansion?

substitutes the value of a variable or a parameter for the name of the variable or parameter when preceded by a $

New cards
56

What does Bash do when it performs arithmetic expansion?

Treats the digits inside double parentheses as numbers performs arithmetic operations on them and substitutes the result of that calculation for the expansion expression

New cards
57

What does Bash do when it performs command substitution?

Runs the commands inside the parentheses in a subshell and substitutes the output from those commands for the substitution expression

New cards
58

What would you write at the command line to define the alias ll whose value was ls -l ?

alias ll='ls -l'

New cards
59

Can an alias be made global?

No

New cards
60

Can a function be made global?

No

New cards
61

What are control structures?

Syntactic structures that control how and when other statements are executed

New cards
62

What are the two basic types of control structures?

Conditionals and loops

New cards
63

What is the basic format of the if ... then construct?

if COMMAND

Then

COMMAND_1

COMMAND_2

fi

New cards
64

How is the command that follows if used to determine whether or not the statements between the then and fi keywords are executed?

If the command returns an exit status of 0 then statements are executed

New cards
65

What does an exit status of 0 mean?

That the command that returned the status code ran without error

New cards
66

What are the two keywords that surround the statements inside an if statement?

then and fi

New cards
67

Can the then keyword appear on the same line as if?

Yes, but only if it is separated from it by a semicolon (;)

New cards
68

What does the test command do?

Analyze a logical expression and return an exit status that tells whether the expression is true or false

New cards
69

What is the value of the exit status returned by test to indicate that the expression is true?

0

New cards
70

Does the command that follows “if” need to be tested?

No, it can be any command that returns an exit status

New cards
71

What do [ and ] mean when used in an if statement?

They stand for the test command

New cards
72

What are the keywords used to mark a block of commands in an if ... then statement?

then and fi

New cards
73

What are the keywords used to mark the first block of commands in an if ... then ... else statement?

then and else

New cards
74

What are the keywords used to mark the second block of commands in an if ... then ... else statement?

else and fi

New cards
75

What are the keywords used to mark the block of commands following elif?

then and either else or elif or fi

New cards
76

Is there any limit to the number of blocks of commands you can have in an if ... else ... elif statement?

No

New cards
77

How would you run the script do_something.sh if you wanted to print each line of the script before it was executed?

bash -x do_something.sh

New cards
78

If you were debugging a script as in the example above, how would Bash mark the lines of the script itself to distinguish them from the output of the script?

By starting each line with a +

New cards
79

What has to follow each elif in an if ... else ... elif statement?

A Unix command

New cards
80

How does the test command indicate that the logical expression it is evaluating is true?

By returning a status code of 0

New cards
81

In a for ... in loop, where does the loop variable get its values?

From the list of values following the keyword in

New cards
82

In a simple for loop, where does the loop variable get its values?

From the command line arguments

New cards
83

Should the loop variable in a for loop have a $ in front of it?

No

New cards
84

In a three statement for loop, what does the first statement do?

Sets the initial value of a loop variable

New cards
85

In a three statement for loop, what does the second statement do?

It's a logical expression and the loop will continue as long as its value is true

New cards
86

In a three statement for loop, what does the third statement do?

changes the value of the loop variable after each pass through the loop

New cards
87

Why are the three statements in a three statement for loop surrounded by two parentheses?

So the values of all variables will be treated as numbers

New cards
88

When does a while loop stop running?

When the command following while returns an exit status that is not 0

New cards
89

What does the continue command in a loop do?

Stops that pass through the loop and returns to the top of the loop

New cards
90

What does the break command in a loop do?

Jumps completely out of the loop

New cards
91

In a case statement, what determines which block of code is executed?

The value of the variable between case and in

New cards
92

How do you mark the end of a code block in a case statement?

;;

New cards
93

What signals the end of a pattern in a case statement?

)

New cards
94

What meta-characters can you use in a case statement pattern?

all of them: ?, * and [ ]

New cards
95

What pattern would you use in a case statement if you wanted to match 11, 12 or 13?

11|12|13

New cards
96

What will you see on the screen if you ran a script that uses the select statement?

A menu of numbers followed by values

New cards
97

What happens to the value chosen by the user when responding to a select statement?

The value is assigned to the select variable

New cards
98

What function does the PS3 keyword shell variable serve in a select statement?

It contains the text used in the menu prompt

New cards
99

How do you mark the beginning of a here document in a shell script?

<< followed immediately by a string with no spaces between them

New cards
100

How do you mark the end of a here document?

With the same string that starts the here document on a line by itself

New cards

Explore top notes

note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 41 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 9 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 19060 people
Updated ... ago
4.8 Stars(181)
note Note
studied byStudied by 15 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 57 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 3915 people
Updated ... ago
4.6 Stars(22)

Explore top flashcards

flashcards Flashcard67 terms
studied byStudied by 111 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard96 terms
studied byStudied by 22 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard38 terms
studied byStudied by 16 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard29 terms
studied byStudied by 6 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard157 terms
studied byStudied by 34 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard54 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard29 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard351 terms
studied byStudied by 1050 people
Updated ... ago
4.7 Stars(11)