0

From man bash,

history -p arg [arg ...]

...

-p

Perform history substitution on the following args and display the result on the standard output.

What does 'history substitution' mean here? Can you provide an example of its use?

Thanks.


I understand command line history substitution, and already tried things like this:

history -p "!23:1"

But this is not dependent on -p, as xx "!23:1" does the same thing.

  • I suspect this is if you turn off history expansion, you still have a way to recall history: try set +H; echo !23; history -p !23 -- re-enable history expansion with set -H – glenn jackman Feb 19 at 20:55
2

If you have history expansion enabled, and run history -p "!23:1", the expansion happens before the history builtin sees the designator !23:1, since history expansion takes place even within double-quotes.

However, if you either disable history expansion, or protect the exclamation mark with single quotes or a backslash, so that the builtin gets to handle it, you'll see that history -p outputs the result of that history expansion:

$ true
$ history -p '!!'
true

I assume the purpose of it is to be able to script history expansions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.