2.2 Basic Bash Syntax Flashcards
How do you start a bash script?
! /bin/bash
How do you comment in a bash script?
comment
When you create a bash script what do you need to do before it can be executable?
Change the file permissions to allow execution.
How do you write a multi-line comment with shell scripting?
Multiple single-line comments, as there is no direct way to create multi-line comments in bash.
What is the syntax for creating a variable in bash?
variable_name=value
How do you call/use a variable?
$variable_name
How do you add a variable to a string?
e.g., echo "text ${variable_name}"
What are the types of variables in bash?
User-defined and environment variables (e.g., HOME, USER, etc.).
How do you collect input from a user in bash?
read variable_name
How do you collect input from a user with a prompt?
read -p ‘message’ variable_name
How do you hide user input as they enter it?
read -sp ‘message’ variable_name
How is arithmetic done in bash?
• 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.