Assign the standard output of date +%Y%m%d to TODAY.
Which statement is appropriate?
$(COMMAND) is command substitution; trailing newlines are removed before the output is assigned.
Detailed explanation
TODAY=date +%Y%m%dIncorrect. The ungrouped command text is not a valid single assignment in this form.
Incorrect. The ungrouped command text is not a valid single assignment in this form.
TODAY=$(date +%Y%m%d)Correct. It executes date and assigns its output to TODAY.
Correct. It executes date and assigns its output to TODAY.
TODAY=${date +%Y%m%d}Incorrect. ${...} performs parameter expansion, not command execution.
Incorrect. ${...} performs parameter expansion, not command execution.
TODAY=$((date +%Y%m%d))Incorrect. $((...)) is arithmetic expansion.
Incorrect. $((...)) is arithmetic expansion.
Try it yourself
An example you can run in a temporary verification environment.
TODAY=$(date +%Y%m%d); printf '%s\n' "$TODAY"Expected result
実行日の8桁の日付Key points
- $(...) is command substitution
- Trailing newlines are removed
- ${...} is parameter expansion
Notes
- Environment: GNU Bash 5.2 / GNU coreutils date
- 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.