Pipe body text to mail, use subject Test, and send to root.
Which command is appropriate?
mail reads the body from standard input, -s supplies the subject, and the positional argument is the recipient.
Detailed explanation
printf 'body\n' | mail -r Test rootIncorrect. -r sets the sender address.
Incorrect. -r sets the sender address.
printf 'body\n' | mail root -f TestIncorrect. -f reads a mailbox file rather than setting the subject.
Incorrect. -f reads a mailbox file rather than setting the subject.
mail -q Test root < bodyIncorrect. -q is not the standard subject option in this form.
Incorrect. -q is not the standard subject option in this form.
printf 'body\n' | mail -s Test rootCorrect. -s Test sets the subject and root is the recipient.
Correct. -s Test sets the subject and root is the recipient.
Try it yourself
An example you can run in a temporary verification environment.
mail --help 2>&1 | grep -E -- '--subject| -s' | head -n 1Expected result
-sまたはsubjectのhelp行(mail実装により形式は異なる)Key points
- Body from stdin
- -s subject
- Recipient argument
Notes
- Environment: mail helpの読取のみ
- 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.