Automation · Bash Automation
Command Substitution
Cheat sheet · https://pcornel.dk/topic.php?topic=5287
Answer
Command substitution runs a command and inserts its output, written $(command), such as today=$(date +%F). Prefer it over backticks and quote it to keep spaces intact.
Remember
- Use $(command), not backticks.
- Quote the result.
- Trailing newlines are removed.
First checks
now="$(date -u +%FT%TZ)"— command substitution- $( ) instead of backticks — readability
- Check command success — set -e doesn't catch in assignments always
Verify in this order
command → stdout captured → variable
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5287