OS515-Workbook6 Flashcards

1
Q

The default shell in Red Hat Enterprise Linux is…?

A

the 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…?

A

interactively, or as 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….?

A

the ~/.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…?

A

the command lines that it executes. Command lines can be retrieved from the history using various history expansions that begin with “!”.

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

See slide 3 for..?

A

command history.

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

Multiple commands can be separated with a…?

A

; (see example on slide 4)

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

The first line of your script must specify…?

A

which interpreter to send instructions to.

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

Before ou can run a script, you must…?

A

enable the “executable” permission on it (otherwise it’s just a text file).

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

If you created a script called foo.sh in your home directory and then just typed foo.sh you would get a….?

A

“no such file or directory” error.

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

Bash shell script example slide…?

A

6

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

Upon exiting, every command returns an integer to its parent called…?

A

a return value. (Examples on slide 7)

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

The shell variable $? expands to the return value of…?

A

previously executed command. (Examples on slide 7)

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

Running Multiple Commands Conditionally:

&& and || conditionally…?

A

separate multiple commands. (Example on slide 8)

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

TASK:
Write a script that will
- Create an empty file called testfile in your home directory.
- Copy the file to the /tmp directory and delete the copy on your home directory of the copy completes successfully.

How do you ensure the scripts runs?

Where to put the script so you can run it?

A

(DO IT YOURSELF)

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

Shell variables are assigned using an…?

A

A=apple syntax

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

Variables are examined (“dereferenced”) with the …?

A

$ character as in echo $A.

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

At the kernel level, every process has a collection of environment variables, which are inherited by…?

A

child processes.

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

The export command converts a shell variable into…?

A

an environment variable.

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

The set and env commands list…?

A

shell variables and environment variables, respectively.

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

Bash Variables:

The variable ? expands to…?

A

The exit status of the most recently executed command.

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

Bash Variables:

The variable - expands to…?

A

Currently enabled shell option flags.

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

Bash Variables:

The variable $ expands to…?

A

Process id (pid) of current shell.

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

Bash Variables:

The variable ! expands to…?

A

Process id (pid) of most recent background command.

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

Bash Variables:

The variable _ expands to…?

A

Last token of previous command.

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

Bash Variables:

The variable PPID expands to…?

A

The process id (pid) of the shell’s parent.

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

Bash Variables:

The variable SHELLOPTS expands to…?

A

Colon separated list of currently enabled shell options, as reported by the set -o command.

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

Bash Variables:

The variable UID expands to…?

A

The userid of the current user.

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

Bash Variables:

The variable BASH_VERSION expands to…?

A

The current bash version.

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

Bash Variables:

The variable HOSTNAME expands to…?

A

The DNS hostname of the current machine.

30
Q

Bash Variables:

The variable OLDPWD expands to…?

A

The previous working directory.

31
Q

Bash Variables:

The variable PWD expands to…?

A

The current working directory.

32
Q

Bash Variables:

The variable RANDOM expands to…?

A

a random number between 0 and 32767.

33
Q

Bash Variables:

The variable SECONDS expands to…?

A

The number of seconds since the shell was started.

34
Q

Environment Variables:

TERM…?

A

Specifies low level configuration of the user’s terminal. This variable is more relevant when using a serial line console (“dumb terminal”) to access the system.

35
Q

Environment Variables:

PATH…?

A

Specifies directories to be searched for executable files.

36
Q

Environment Variables:

DISPLAY..?

A

Specifies which X server clients should use in the graphical environment.

37
Q

Environment Variables:

LANG…?

A

Specifies the preferred language for internationalized programs.

38
Q

Environment Variables:

EDITOR…?

A

Many programs rely on an external editor for user input. Often, the default editor is vi. If the EDITOR environment variable is set, the specified editor will be used instead.

39
Q

Environment Variables:

PRINTER…?

A

Most commands that submit or manage print jobs will examine this environment variable to determine the default printer.

40
Q

The bash shell expands certain command line …?

A

metacharacters before interpreting the command.

41
Q

Tilde expansion expands tokens that begin with…?

A

a tilde (~) to users home directories.

42
Q

Brace expansion expands tokens with …?

A

braces ({}) into multiple words, each of which contains a single word from the specified list.

mkdir {dir1, dir2, dir3}/{subdir1,subdir2}

mkdir dir1
mkdir dir1/subdir1
mkdir dir1/subdir2
…etc…

43
Q

Command substitution expands text enclosed within…?

A

backticks (“) or “dollar parenthesis” ($()) into the output produced by the enclosed command.

VAR=’COMMAND’

FILES=’ls/etc’
FILES=$(ls /etc)

44
Q

Double quotes (“…”(, single quotes (‘…’), and the backslash character can be used to…?

A

protect characters from being expanded by the shell.

NUMBER=1234

echo “testing $NUMBER > file”
echo testing $NUMBER > file
echo ‘testing $NUMBER > file’

45
Q

Arithmetic Expansion:

The bash shell treats text wrapped with a $((…)) syntax as an…?

A

arithmetic operation.

46
Q

Arithmetic Expansion:
Variables are treated as numeric integers where appropriate, and standard mathematical operators such as +, -, * and / are treated as…?

A

such.

[prince@station prince]$ WIDTH=16
[prince@station prince]$ HEIGHT=82
[prince@station prince]$ echo $(( $WIDTH * $HEIGHT)) 1312

47
Q

Within a bash script, any arguments provided when the script was invoked, are available as…?

A

positional parameters (i.e, the variables $1, $2, …).

48
Q

The read builtin command can be used to read…?

A

input from the keyboard (“standard in”).

49
Q

The bash shell uses a if …. then …. [else …] fi syntax to…?

A

implement conditional branches.

50
Q

The test command is often used as the…?

A

conditional command in if … then branches.

51
Q

The bash shell uses a for … in …do …done syntax to…?

A

implement loops.

52
Q

The if statement…?

A

if condition
then
commands
fi

if condition
then 
	commands
else
	commands
fi
53
Q

Testing conditions

You can use test or…?

A

test -f /etc/hosts

54
Q

Testing conditions

You can use […?

A

[ f /etc/hosts ]

55
Q

Testing conditions:

The expression -d FILE has the condition of…?

A

FILE exists, and is a directory.

56
Q

Testing conditions:

The expression -e FILE has the condition of…?

A

FILE exists.

57
Q

Testing conditions:

The expression -f FILE has the condition of…?

A

FILE exists, and is a regular file.

58
Q

Testing conditions:

The expression -r FILE has the condition of…?

A

File exists, and is readable.

59
Q

Testing conditions:

The expression -w FILE has the condition of…?

A

File exists, and is executable.

60
Q

Testing conditions.

The expression FILE1 -nt FILE2 has the condition of …?

A

FILE1 is newer than FILE2.

61
Q

Testing conditions:

The expression EXPRESSION1 -a EXPRESSION2 has the condition of…?

A

Both EXPRESSION 1 and EXPRESSION 2 are true.

62
Q

Testing conditions:

The expression EXPRESSION1 -o EXPRESSION2 has the condition of…?

A

Either EXPRESSION1 or EXPRESSION2 is true.

63
Q

Testing conditions:

The expression !EXPRESSION has the condition of…?

A

EXPRESSION is false.

64
Q

Testing conditions:

The expression [-n] STRING has the condition of…?

A

the length of STRING is greater than zero.

65
Q

Testing conditions:

The expression -z STRING has the condition of…?

A

the length of String is zero.

66
Q

Testing conditions:

The expression STRING1 = STRING2 has the condition of…?

A

STRING1 and STRING2 are equal.

67
Q

Testing conditions:

The expression STRING1 = STRING has the condition of…?

A

STRING1 and STRING2 are not equal.

68
Q

Loop statement…?

A

for var in list
do
Commands
done

69
Q

Loop statement…?

A

for i in $*

for i in /etc/*.conf

for i in $(command)

70
Q

Loop statement example…?

A
[elvis@station elvis]$ cat pack
#!/bin/bash
for DIR in $*
do
	if [ -d $DIR ]
	then
		if [ "$DIR" == "." -o "$DIR" == ".." ]
		then
			echo "skipping directory $DIR“
		else
			tar cvzf $DIR.tgz $DIR && rm -fr $DIR
		fi
	else
		echo "skipping non directory $DIR“
	fi
done