# Essential Bash Scripting Flashcards

Table of Contents

1. Shell Scripting Flashcards

1.1. What is the shebang line for a bash script?   drill shell_scripting

1.1.1. Front

What is the shebang line for a bash script?

1.1.2. Back

#!/bin/bash

1.2. How do you declare a variable in bash?   drill shell_scripting

1.2.1. Front

How do you declare a variable in bash?

1.2.2. Back

variable_name=value

(No spaces around the equal sign)

1.3. What is the syntax for an if statement in bash?   drill shell_scripting

1.3.1. Front

What is the syntax for an if statement in bash?

1.3.2. Back

if [ condition ]; then
    # commands
elif [ condition ]; then
    # commands
else
    # commands
fi

1.4. How do you access command-line arguments in a bash script?   drill shell_scripting

1.4.1. Front

How do you access command-line arguments in a bash script?

1.4.2. Back

$1, $2, $3, etc. for individual arguments
$@ for all arguments
$# for the number of arguments

1.5. What is the syntax for a for loop in bash?   drill shell_scripting

1.5.1. Front

What is the syntax for a for loop in bash?

1.5.2. Back

for variable in list
do
    # commands
done

1.6. How do you define a function in bash?   drill shell_scripting

1.6.1. Front

How do you define a function in bash?

1.6.2. Back

function_name() {
    # commands
}

1.7. What command is used to read user input in bash?   drill shell_scripting

1.7.1. Front

What command is used to read user input in bash?

1.7.2. Back

read variable_name

1.8. How do you perform arithmetic operations in bash?   drill shell_scripting

1.8.1. Front

How do you perform arithmetic operations in bash?

1.8.2. Back

Using double parentheses: $((expression))
Example: result=$((5 + 3))

1.9. What is the purpose of the 'export' command in bash?   drill shell_scripting

1.9.1. Front

What is the purpose of the 'export' command in bash?

1.9.2. Back

To make a variable available to child processes (subshells)

1.10. How do you redirect output to a file in bash?   drill shell_scripting

1.10.1. Front

How do you redirect output to a file in bash?

1.10.2. Back

> : Overwrite the file
>> : Append to the file
Example: echo "Hello" > output.txt