How can I recall a command from history by number without executing it?

How can I grab a command from history by number to my command line without executing it?

This immediately executes command number 555 which I'm not looking for:
$ history 10
$ !555

This opens the command up in an editor, which is overkill most of the time:
$ history 10
$ fc 555

This is an example of what I'm looking for:
$ history 10
$ #555
$ [command 555 from history listing now sitting here on my command line ready to edit or execute]

Thank you!


Solution 1:

shopt -s histverify

If the histverify shell option is enabled, and Readline is being used, history substitutions are not immediately passed to the shell parser. Instead, the expanded line is reloaded into the Readline editing buffer for further modification.

Solution 2:

Add :p after the digits.

Example:

1357  locate pam_loginuid
1358  history
rinzwind@discworld:~$ !1358:p
history
rinzwind@discworld:~$ !1357:p
locate pam_loginuid
rinzwind@discworld:~$ 

Printed to display and not executed.

For using it in BASH you need to do more. Example:
https://tldp.org/LDP/abs/html/histcommands.html

#!/bin/bash
set -o history
var=$(history); echo "$var"   # 1  var=$(history)`

will put all of history into var and you need some more logic to find the command you want.