Inspect commands already run in the current interactive Bash session.
Display them together with history numbers.
Which shell builtin should be used?
The Bash history builtin prints the current history list with its numbers, which helps locate commands for review or reuse.
Detailed explanation
manIncorrect. man displays manual pages and does not list session history.
Incorrect. man displays manual pages and does not list session history.
historyCorrect. history prints the loaded history list with numbers.
Correct. history prints the loaded history list with numbers.
envIncorrect. env displays environment variables.
Incorrect. env displays environment variables.
pwdIncorrect. pwd displays the current working directory.
Incorrect. pwd displays the current working directory.
Try it yourself
An example you can run in a temporary verification environment.
bash -ic 'history -s "printf demo"; history 1' 2>/dev/nullExpected result
履歴番号とprintf demoを含む1行Key points
- history is a shell builtin
- The list has history numbers
- It is used in interactive shells
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.