Print accepted when answer is yes, YES, or y.
Use one case clause for all three patterns.
Which case clause is appropriate?
case uses pattern1|pattern2) to combine alternative patterns in one clause. The first matching clause is selected.
Detailed explanation
yes|YES|y) echo accepted ;;Correct. The three alternatives are combined with | before the closing parenthesis.
Correct. The three alternatives are combined with | before the closing parenthesis.
yes,YES,y) echo accepted ;;Incorrect. Case alternatives are not separated with commas.
Incorrect. Case alternatives are not separated with commas.
yes && YES && y) echo accepted ;;Incorrect. && is a command-list operator, not a pattern separator.
Incorrect. && is a command-list operator, not a pattern separator.
[yes YES y]) echo accepted ;;Incorrect. Brackets do not represent a list of literal case alternatives this way.
Incorrect. Brackets do not represent a list of literal case alternatives this way.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'answer=YES; case $answer in yes|YES|y) echo accepted ;; *) echo rejected ;; esac'Expected result
acceptedKey points
- | separates alternatives
- ) starts the clause body
- Close the case with esac
Notes
- Environment: POSIX sh / 状態変更なし
- 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.