Shell Scripts Flashcards

1
Q

What is a shebang?

A

!

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

Is a shebang mandatory for a script?

A

No, if no shebang is found the user configured shell will be used.

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

What permissions we need to set to be able to run a shell script?

A

755, u+x, +x

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

Can you define variables in a shell script?

A

Yes, VARIABLE_NAME=”Value”

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

Is this a correct way to define a variable variable_name=”value”

A

yes

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

is this a correct way to define a variable VARIABLE_NAME= “Value”

A

No, there should no be spaces before or after the equal sign.

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

What’s the syntax to reference a variable inside a shell script?

A

Two ways: $VARIABLE or ${VARIABLE}

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

How can we store the output of a command in a variable?

A

VARIABLE=$(ls), you can also use backticks VARIABLE=ls, backticks is an older syntax, prefer dollar sign.

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

Is this a valid variable name 1FIRST=”Value”?

A

No, variables can’t start with numbers

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

What command should we use for test things inside of a shell script?

A

test

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

what’s the syntax of a test command inside of a shell script?

A

[ condition-to-test ] notice the spaces between the brackets, those are important, otherwise it won’t work.

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

Can you compare strings with test?

A

Yes, [ STRING1 = STRING2 ]

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

Can we use if statements in shell scripts?

A

Yes, in combination with test

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

Apart from if, what other syntax can you use for if cases in shell scripts?

A

if, then, else, elif, fi

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

Is there a way to loop in a shell script?

A

Yes, with for/do/done

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

What does $0 in a shell script means?

A

That’s the first parameter which is the name of the script

17
Q

How can we get the third parameter of a script

A

$3

18
Q

How can we reference all the parameters that are passed to a shell script

A

$@

19
Q

What command should we use in shell script to let user enter some values from stdin and grab them in script?

A

read -p “Enter some value” VARIABLE

20
Q

How can we write comments in a shell scripts?

A

any line that starts with # is a comment in a shell script and it’s ignore by the interpreter