uname -r prints the running kernel release string.
Save that output in LAB_KERNEL.
Which command is appropriate?
Command substitution $(...) is replaced by standard output. Combining it with an assignment stores the result in a shell variable.
Detailed explanation
LAB_KERNEL='uname -r'Incorrect. Single quotes store the literal text uname -r.
Incorrect. Single quotes store the literal text uname -r.
uname -r > LAB_KERNELIncorrect. Redirection writes a file named LAB_KERNEL rather than assigning a variable.
Incorrect. Redirection writes a file named LAB_KERNEL rather than assigning a variable.
$(uname -r)Incorrect. A command substitution by itself is not an assignment.
Incorrect. A command substitution by itself is not an assignment.
LAB_KERNEL=$(uname -r)Correct. The command's output is substituted and assigned to LAB_KERNEL.
Correct. The command's output is substituted and assigned to LAB_KERNEL.
Try it yourself
An example you can run in a temporary verification environment.
LAB_KERNEL=$(uname -r)
printf '%s
' "$LAB_KERNEL"Expected result
uname -rと同じリリース文字列Key points
- Command substitution
- Standard output
- Variable assignment
Notes
- Environment: Bash 5.2 / GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.