2.2 Basic Bash Syntax Flashcards

1
Q

How do you start a bash script?

A

! /bin/bash

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

How do you comment in a bash script?

A

comment

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

When you create a bash script what do you need to do before it can be executable?

A

Change the file permissions to allow execution.

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

How do you write a multi-line comment with shell scripting?

A

Multiple single-line comments, as there is no direct way to create multi-line comments in bash.

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

What is the syntax for creating a variable in bash?

A

variable_name=value

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

How do you call/use a variable?

A

$variable_name

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

How do you add a variable to a string?

A

e.g., echo "text ${variable_name}"

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

What are the types of variables in bash?

A

User-defined and environment variables (e.g., HOME, USER, etc.).

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

How do you collect input from a user in bash?

A

read variable_name

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

How do you collect input from a user with a prompt?

A

read -p ‘message’ variable_name

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

How do you hide user input as they enter it?

A

read -sp ‘message’ variable_name

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

How is arithmetic done in bash?

A

• Addition: Use expr $a + $b to add two numbers.
• Subtraction: Use expr $a - $b to subtract the second number from the first.
• Multiplication: Use expr $a * $b to multiply two numbers (escape * with a backslash).
• Division: Use expr $a / $b to divide the first number by the second.

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