During a security code review, you are asked to rewrite a line in a Bash maintenance script. The variable DATA already contains sensitive information that must be converted to uppercase and stored in NEWDATA. The solution must 1) avoid creating temporary files, 2) invoke no additional utilities except tr, and 3) use the shell redirection operator that is specifically intended to feed a short string directly into a command's standard input. Which of the following one-liners satisfies all three requirements?
The here-string operator <<< is a shell redirection that expands its word and delivers the resulting single string (with a terminating newline) to the standard input of the preceding command. Therefore tr '[:lower:]' '[:upper:]' <<< "$DATA" meets every requirement: only tr is executed, no temporary files are created, and the variable's contents are provided via a here string.
<< "$DATA" is the opening token for a here-document; Bash would interpret the variable's value as the end-delimiter and wait for additional input, so it does not pass the variable to tr.
< "$DATA" redirects the contents of a file named by the expansion of $DATA; unless the variable contains a valid filename this fails and still violates the "no temporary file" rule.
echo "$DATA" | tr … works functionally but invokes the extra command echo, which the constraints forbid, and it uses a pipeline rather than the operator designed for feeding a short string to standard input.
Hence only the command that employs the <<< here-string is correct.
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 the purpose of the `<<<` here-string operator in Bash?
Open an interactive chat with Bash
How is a here-document (`<<`) different from a here-string (`<<<`) in Bash?
Open an interactive chat with Bash
Why is `echo | tr` not suitable for meeting the given script constraints?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
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 .