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. !$ expands to the last argument, not the whole command.
!!Correct. !! expands to the complete previous history command.
!?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 / 一時的な対話シェル
- Use disposable shell sessions and harmless commands for experiments.
- Shell behavior can depend on Bash options and distribution defaults.
Foundation review
Place the operation
The event designator determines how much of the previous command is substituted before execution.
Check the side effect
Inspect the expanded line before running a history substitution that could be destructive.