A system administrator is writing a script that creates a daily backup. The script must use the path from the BACKUP_TARGET environment variable. If BACKUP_TARGET is unset or empty, the script should use /var/backups as the target for that command only, without permanently changing the variable. Which of the following commands correctly achieves this?
The correct syntax for using a default value for an unset or null variable for a single operation is ${parameter:-word}. This form of parameter expansion substitutes the word if the parameter is unset or null, but does not alter the state of the variable itself.
The command cp /var/log/app.log "${BACKUP_TARGET:-/var/backups}/app-$(date +%F).log" correctly uses this syntax.
The syntax ${parameter:=word} would also use the default value, but it would incorrectly assign /var/backups to the BACKUP_TARGET variable if it was unset or null, which is against the requirements.
Using $() executes a command substitution, which is incorrect for this purpose as it attempts to execute the contents as a command.
Using () creates a subshell, which is also incorrect syntax for providing a default value to a variable within a string.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is parameter expansion in Linux?
Open an interactive chat with Bash
Why is `${parameter:-word}` preferred over `${parameter:=word}` in the given script?
Open an interactive chat with Bash
What is the difference between `${parameter:-word}` and `()` or `$()` in this context?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .