1/50
Looks like no tags are added yet.
What is a shell script?
A file of commands run by a shell
What is the first line #!/bin/bash called?
A shebang
How do you run a script in the current folder that is executable?
./script.sh
How do you run a script with Bash without execute permission?
bash script.sh
How do you write a comment in Bash?
Start it with #
How do you assign the value 5 to x?
x=5
Are spaces allowed around = in a Bash assignment?
No
How do you read a variable's value?
$x or ${x}
Why quote "$var"?
To prevent word splitting and filename expansion
What do single quotes do?
Keep text literal
What do double quotes allow?
Variable and command substitution
What does $(command) do?
Substitutes the command's output
What does $((2 + 3)) produce?
5
What is $0?
The script or shell name
What is $1?
The first argument
What is $#?
The number of arguments
What does "$@" represent?
All arguments as separate words
What does shift do?
Moves positional arguments down
How do you read user input into name?
read -r name
What does read -p do in Bash?
Shows a prompt before reading
Which keyword ends an if block?
fi
Which keyword starts the alternative branch of an if?
else
Which keyword adds another condition to an if?
elif
What does [ -f file ] test?
Whether a regular file exists
What does [ -d folder ] test?
Whether a directory exists
What does [ -e path ] test?
Whether a path exists
What does [ -z "$x" ] test?
Whether the string is empty
What does [ -n "$x" ] test?
Whether the string is not empty
What does -eq compare?
Whether two integers are equal
What does -lt mean?
Less than
What does -gt mean?
Greater than
Which keyword ends a for or while loop?
done
How do you loop over all .txt files?
for f in *.txt; do … done
What does a while loop do?
Repeats while its condition succeeds
What does an until loop do?
Repeats until its condition succeeds
What does break do?
Exits a loop
What does continue do?
Skips to the next loop iteration
Which keyword ends a case block?
esac
How do you define a function named greet?
greet() { …; }
What does local do in a Bash function?
Limits a variable to the function's scope
What does return set in a function?
Its exit status
What exit status means success?
0
What does exit 1 indicate?
The script ended with an error
What does set -u do?
Treats use of unset variables as an error
What does set -o pipefail do?
Makes a pipeline fail if any command in it fails
What does bash -n script.sh check?
Syntax without running the script
What does bash -x script.sh show?
Commands as they execute
Which tool finds common shell script mistakes?
ShellCheck
What does trap do?
Runs commands when a signal or shell event occurs
How do you create an array in Bash?
items=(one two three)