FlashKeepers

Linux · CompTIA Linux+

Linux Shell Scripting Basics

Basic bash shell scripting concepts including variables, loops, and conditionals.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone
How do you declare and assign a variable in bash?
VARIABLE_NAME=value (no spaces around the equals sign)
What is the syntax to reference a variable's value in bash?
$VARIABLE_NAME or ${VARIABLE_NAME}
What command exports a variable so it is available to child processes?
export VARIABLE_NAME
How do you assign the result of a command to a variable?
VARIABLE=$(command) or VARIABLE=`command`
What is the difference between single quotes and double quotes in bash?
Double quotes allow variable expansion and command substitution; single quotes treat everything literally
What does the read command do in a bash script?
Reads input from the user and stores it in a variable
What is the basic structure of an if statement in bash?
if [ condition ]; then commands; fi
How do you test if a file exists in an if statement?
if [ -f /path/to/file ]; then
How do you test if a directory exists in an if statement?
if [ -d /path/to/directory ]; then
What does the -z flag test for in a condition?
Tests if a string is empty (zero length)
What does the -n flag test for in a condition?
Tests if a string is not empty (has length)
How do you compare two numbers in an if statement?
Use -eq, -ne, -lt, -le, -gt, or -ge inside brackets
What is the syntax for an if-else statement in bash?
if [ condition ]; then commands; else commands; fi
What is the syntax for an if-elif-else statement in bash?
if [ condition1 ]; then commands; elif [ condition2 ]; then commands; else commands; fi
What is the basic structure of a for loop in bash?
for variable in list; do commands; done

25 more cards in the app