Bash variables, quoting rules, parameter expansion, command substitution, arithmetic, globbing and exit codes.
38 cards · basic cards · AI-written, checked twice. Edit anything.
- How do you assign a value to a variable in Bash?
Show answer
var=value with no spaces around the equals sign
- How do you access the value of a variable?
Show answer
Prefix the variable name with a dollar sign: $varname or ${varname}
- What characters are allowed in Bash variable names?
Show answer
Alphanumeric characters and underscore; first character must be a letter or underscore
- How do you remove a variable from the shell environment?
Show answer
Use the unset command: unset varname
- What is an environment variable?
Show answer
A shell variable that is exported and inherited by child processes
- How do you export a variable to make it available to child processes?
Show answer
Use the export command: export varname
- What do single quotes prevent in Bash?
Show answer
All expansions and interpretations; everything inside single quotes is treated literally
- Which special characters trigger expansion inside double quotes?
Show answer
Dollar sign ($) for variable and command substitution, and backtick for command substitution
- What happens when you use a variable without quotes if it contains spaces?
Show answer
The variable value undergoes word splitting and pathname expansion (globbing)
- What quoting style allows ANSI escape sequences like \n and \t?
Show answer
$'...' (ANSI-C quoting)
- How do you include a literal single quote inside a single-quoted string?
Show answer
End the single-quoted string, add an escaped single quote \', then resume: 'can'\''t'
- How do you prevent a dollar sign from triggering variable expansion?
Show answer
Escape it with a backslash: \$ inside double quotes
- What is the result if you expand an unset variable inside double quotes?
Show answer
An empty string
- Can backslash escape characters inside single quotes?
Show answer
No; backslash is literal inside single quotes
- What is the advantage of using ${var} instead of $var?
Show answer
Braces are unambiguous when the variable name is followed by alphanumeric characters