Bash and its exclamation mark command, preview actual command before executing it

bashcommand history

! as a prefix to some string will execute whatever command in the command buffer that starts with the (partial) string given. There are also some other uses for it. See e.g. Understanding the exclamation mark (!) in bash

My question is, how can I preview what command will be executed before executing it? E.g. if I do !for, and I've written several commands starting with 'for' previously, but I'm not completely sure if the one I think was the last one is indeed the one I think. It would be very useful if bash could show me what the command that would be executed is before I actually execute it. Is there any way to do this in bash?

Best Answer

Bash has inherited the ! mechanism from csh. The way to preview your command in both shells is to add a :p to the end.

!for:p