Variables Flashcards

1
Q

how do you write a function?

A

name () {
commands
return
}

or

function myfunc {
echo “hello $1”
}

Usage:
myfunc “John”

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

What is top down design?

A

Process of identifying top-level steps and developing increasing detailed views of those steps.

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

Shell functions are:

A

“Mini-scripts” located inside other scripts and can as as autonomous programs.

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

Bash Shebang?

A

#!/usr/bin/env bash

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

How to make a script executable?

A

chmod +x [SCRIPT NAME]
./[SCRIPT NAME]

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

How are variables written:

A

String:
VARIABLE=”string”
or
Numerical Value:
VARIABLE=[NUMBER]

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

a=z

A

Assign the string “z” to variable a.

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

b=”a string”

A

Embedded spaces must be within quotes

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

c=”a string and $b”

A

Other expressions such variables can be expanded into a variable

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

d=”$(ls -l foo.txt)”

A

Variable is the result of the cmd

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

e=$((5 * 7))

A

Arithmetic expression

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

f=”\t\ta string\n”

A

Escape sequence such as tabs and new lines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
Variable result of: 
filename="myfile" 
#mv "$filename" "${filename}1"
A

myfile1

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

Quoting in variables:

A

Good practice to enclose variables and cmd substitutions in double quotes to limit the effects of word-splitting by the shell.

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

echo $LINENO = ?

A

This will print the line number in the script where this echo line was ran.

Probably helpful for writing your own error codes

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