Linux+ Basic Bash Scripting Flashcards
7 cards from real Linux practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Linux+ Basic Bash Scripting flashcards as text
What does `trap 'echo caught' SIGINT` do in a Bash script?
Answer: Runs 'echo caught' when the script receives SIGINT (Ctrl+C)
trap sets up a handler so that when SIGINT is received, the specified command executes instead of the default behavior.
Which option to `bash` runs the script but only checks for syntax errors without executing?
Answer: -n
bash -n reads the script and reports syntax errors but does not execute any commands.
What is the output of: `echo ${myvar:-default}` when myvar is unset?
Answer: default
The :- parameter expansion returns the fallback value 'default' when the variable is unset or empty.
Which command sends a script to run in the background and returns the shell prompt immediately?
Answer: Appending & to the command
Appending & to a command runs it as a background job, returning control to the shell immediately.
In Bash, what does `local` do when used inside a function?
Answer: Restricts the variable's scope to the function only
local declares a variable whose scope is limited to the enclosing function and its children, preventing global namespace pollution.
What does `source ./config.sh` (or `. ./config.sh`) do?
Answer: Executes config.sh in the current shell, sharing its variables
source (or .) executes the script in the current shell session, so any variables or functions it defines become available immediately.
Which Bash test operator checks if file1 is newer than file2?
Answer: file1 -nt file2
The -nt (newer than) operator returns true if file1's modification time is more recent than file2's.