In an interactive Bash, run the immediately previous command again unchanged.
History expansion is enabled.
Which history designator should be entered?
In interactive Bash, !! expands to the complete previous history entry. !$ expands only to the previous command's final argument.
Detailed explanation
!0Incorrect. !0 is not the usual designator for the immediately previous command.
Incorrect. !0 is not the usual designator for the immediately previous command.
!$Incorrect. !$ expands to the last argument, not the whole command.
Incorrect. !$ expands to the last argument, not the whole command.
!!Correct. !! expands to the complete previous history command.
Correct. !! expands to the complete previous history command.
!?Incorrect. !? requires a search string to form a history reference.
Incorrect. !? requires a search string to form a history reference.
Try it yourself
An example you can run in a temporary verification environment.
bash -ic 'set -H; echo first; !!' 2>/dev/nullExpected result
firstが2回表示される(履歴展開後のコマンド表示を伴う場合がある)Key points
- !! means the previous command
- !$ means the previous final argument
- History expansion is primarily interactive
Notes
- Environment: Bash 5.x / 一時的な対話シェル
- 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.