Lesson 4 PL | Shell Scripting Flashcards

(79 cards)

1
Q

The first line that identifies the file as a bash script

A

!/bin/bash

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

Comments begin with ____ and end at the end of the line

A

#

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

Gives the user (and others, if she wishes permission to execute it.

A

chmod +x filename

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

How to run a file from local dir.

A

./filename

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

Run with a trace - echo commands after expansion

A

bash -x ./filename

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

How to create a variable

A

Variablename=value (no spaces, no $)

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

How to read variable name?

A

read variablename (no $)

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

How to access a variable’s value

A

$variablename

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

Refereces the name of the script.

A

$0

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

Holds the value of the number of positional parameters

A

$#

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

Lists all of the positional parameters

A

$*

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

Means the same as $@, except when enclosed in double quotes

A

S@

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

Expands to a single argument (e.g., “$1 $2 $3”)

A

”$*”

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

Expands to separate arguments (e.g., “$1” “$2” “$3”)

A

“S@”

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

Command to reset the script arguments

A

set

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

Shows all the environment variables that exist

A

set | more

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

___ and ___ can be used as part f the list in a for loop or can be used as part of it

A

$* and $@

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

___ is evaluated to a single string

A

$*

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

___ is evaluated to a list of separate word

A

$@

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

What does <ctrl> do?</ctrl>

A

Exit new process

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

Reads a line from stdin into the variable answer

A

read answer

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

Reads a line from stdin up the whitespace, putting the first word in frsit and the rest of the line into last

A

read first last

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

Reads a line from stdin and assigns it to REPLY

A

read

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

Reads a list of word into an array called arrayname

A

read -a arrayname

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Prints a prompt, waits for input and stores input in REPLY
read -p prompt
26
Allows the input to contain a backlash
read -r line
27
____ in a number makes it be interpreted as octal
Leading 0
28
___ in a number makes it to be interpreted as hex
Leading 0x
29
_____ in a number makes it interpreted as that base
Leading #
30
Bash does not support floating point arithmetic but ____,____, and ____ utilities do
bc, awk, and nawk
31
Unary string test
- [ string ] (not null) - -z (0 length) - -n (some length) - -l (returns the length of the string)
32
[ string ]
String is not null
33
[ -z string ]
Length of string is zero
34
[ -n string ]
Length of string is nonzero
35
[ -l string ]
Length of string (number of character)
36
[ string1 -a string2 ]
Both string1 and string2 are true
37
[ string1 -o string2 ]
Both string1 or string2 are true
38
[ ! string ]
Not a string1 match
39
[[ pattern1 && pattern2 ]]
Both pattern1 and pattern2 are true
40
[[ pattern1 || pattern2 ]]
Either patern1 or patern2 is true
41
[[ !pattern ]]
Not a patern match
42
What does this mean? -eq
Equal
43
What does this mean? -ne
not equal
44
What does this mean? -ge
greater than or equal
45
What does this mean? -gt
greater than
46
What does this mean? -lt
less than
47
What does this mean? -le
less than or equal
48
What does this mean? -nt
New file
49
What does this mean? -ot
Older file
50
What does this mean? -ef
Have the same device and inode numbers
51
What does this mean? -b
Block special file
52
What does this mean? -c
Character special file
53
What does this mean? -d
Directory existence
54
What does this mean? -e
File existence
55
What does this mean? -f
Regular file existence and not a directory
56
What does this mean? -G
True if file exists and is owned nu the effective group id
57
What does this mean? -g
Set-group-ID is set
58
What does this mean? -k
Sticky bit is set
59
What does this mean? -L
File is a symbolic link
60
What does this mean? -p
File is a named pipe
61
What does this mean? -O
File exists and is owned by the effective user ID
62
What does this mean? -r
File is readable
63
What does this mean? -S
File is a socket
64
What does this mean? -s
File is nonzero size
65
What does this mean? -t fd
True if fd (file descriptor) is opened on a terminal
66
What does this mean? -u filename
Set-user-id bit is set
67
What does this mean? -w filename
File is writable
68
What does this mean? -x
File is executable
69
The ___ in bash is a shell variable that contains a numeric value representing the exit status
?
70
0 = ___ 1 = ____
0 = Sucess 1 = Failure
71
___ is used to terminate the script; it is mainly to used to exit the script if some condition is true
exit
72
____ has one parameter - a number ranging from 0 to 255, indicating if is ended succcessfully (0) or unsucessfully (nonzero)
exit
73
the ____ evaluates the command following it and, if its exit status is 0 the commands in the body of the loop are execcuted
while command
74
____ works like the while command, except it execute the loop if the exit status is nonzero (e.g., command failed)
until command
75
___ allows the user to create menus in bash
select
76
___ will automatically repeat and has do mechanisms of its own to terminate
select
77
We use ____ to force an immediate exit from a loop (but not the program)
break
78
we use ____ to shift the parameter list one or more places to the left, removing the displayed parameters
shift
79
send back information with ____ statement
return