Introduction to Bash Flashcards

1
Q

The default shell in Red Hat Enterprise Linux is the…?

A

bash shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The bash shell can be used interactively, or as a….?

A

powerful scripting language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Upon startup, bash executes commands found in the…?

A

~/.bashrc file, allowing users to customize their shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The bash shell maintains a history of the command lines that it executes. Command lines can be retrieved from the history using various history expansions that begin with….?

A

”!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In Linux, the shell is the most commonly used program. The shell is what you see when you…?

A

log in or open a terminal, and is what you use to start most every command.

(Although there are a variety of different shells available, they all provide the same basic behavior: listen for commands from the user, start processes as specified in those commands, and report the results back to the user)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The most commonly used shell in Linux is the bash shell, which is the default shell in…?

A

Red Hat Enterprise Linux.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Shell scripts allow users to automate often repeated actions by combining a series of…?

A

commands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Unlike interactive shells, shell scripts usually run a series of commands…?

A

non-interactively, and many of the features of the bash shell provide programming logic (such as branches or loops) for writing sophisticated scripts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In practice, users seldom need to start a shell…?

A

manually. Whenever someone logs in, or opens a terminal, a shell is started automatically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Occasionally, however, users would like to run a different shell, or another instance of the same shell. Because the shell is “just another” program, new shells can be launched from an existing shell. The new shell is referred to as a…?

A

subshell of the original shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When the subshell is exited, control is returned to the …?

A

original shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When starting a bash subshell, the apparent differences between the subshell and the parent shell are…?

A

minimal, and care must be taken to keep track of which shell you are in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

As part of its initialization, the bash shell will look for a file titled…?

A

.bashrc in a user’s home directory. This file is used to customize the bash shell.

(As the shell starts, commands listed in this file are executed as if they were entered on the command line. Technically, the bash shell “sources” the file. )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Interactive shells continuously repeat a cycle of listening for a…?

A

command line, evaluating the requested command and performing any requested actions, and displaying the results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The shell listens to the keyboard for input, and uses the RETURN key to recognize the…?

A

end of input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

As a convenience to users of interactive shells, the bash shell keeps a history of each command entered by the user, and provides a variety of ways to make commands from this history available at the finger tips. The easiest way to view your current history is to use the……?

A

history command.

17
Q

As an alternative to the arrow keys, the bash shell also performs “history substitution”, which is triggered by…?

A

the exclamation point.

18
Q

Bash History Substitution:
Syntax: !!
Substitution: ????

A

Previous Command.

19
Q

Bash History Substitution:
Syntax: !n
Substitution: ????

A

Command number n

20
Q

Bash History Substitution:
Syntax: !-n
Substitution: ????

A

The nth most recent command.

21
Q

Bash History Substitution:
Syntax: !cmd
Substitution: ????

A

The most recent command that began cmd

22
Q

Not only does the bash shell maintain a command history within a session, but the shell also preserves command histories between sessions. When the bash shell exits, it dumps the current command history into a file called….?

A

.bash_history in a user’s home directory. Upon startup, the shell initializes the command history from the contents of this file.

(What repercussions does this have for multiple interactive shells (owned by the same user) running at the same time? Because the history is only saved to disk as the shell exits, commands executed in one bash process are not available in the command history of a simultaneously running bash process. Also, the last shell to exit will overwrite the histories of any shells that exited previously.)

23
Q

Bash Shell Command History Variables
Variable: HISTFILE
Default Value: ~/.bash_history
Effects: ?????

A

The file to which the command history is saved on exit and from which it is initialized on startup.

24
Q

Bash Shell Command History Variables
Variable: HISTFILESIZE
Default Value: 1000
Effects: ?????

A

The file HISTFILE will be truncated to this size on startup.

25
Q

Bash She Command History Variables
Variable: HISTSIZE
Default Value: 1000
Effects: ????

A

The maximum number of commands that willl be written to teh file HISTFILE on exit.

26
Q

ESC+. and ALT+. ….?

A

The last token of the previously typed command line can be recovered with these two commands.

. Once learned, this little trick comes in handy surprisingly often. The last token of a command often represents the object that someone is handling. For example, someone might make a directory, and then immediately cd to it, or edit a file, and immediately want to use chmod to change its permissions. If the key sequence is repeated, the bash shell will continue to cycle through the last tokens of earlier command lines.

27
Q

CTRL+R …?

A

This key sequence mimics !cmd in spirit. Text typed after the CTRL+R key sequence is matched against previously typed commands, with the added advantage that matching command lines are viewed immediately as the text is typed. You also have the opportunity to edit the recalled line (using the LEFT and RIGHT arrow keys, or other command line editing keystrokes) before executing the command.

28
Q

fc …?

A

The fc command allows users to “fix” the previously entered command, by opening up the user’s default editor (vi by default) with the previously entered command as text. Upon exiting the editor (presumably after somehow editing the command), the new text will be immediately executed. For those proficient in quickly exiting an editor, the command comes in handy.