1

I could do:

!systemctl:p to get systemctl reload bind result printed (as last command in the history starting with systemctl string).

but doing the same with the partial search on the command history:

!?reload:p results in zsh: no such event: reload:p

the former looks the most recent event in the history that starts with systemctl string and prints it on the screen, thanks to :p modifier, instead of executing.

i thought :p is true for !? as well on any shell.

and also results in bash: !?reload:p: event not found.

how can i achieve the printing and not executing of the found command line on partial command history search in common unix shells?

1

Per the manual (emphasize mine):

!?str[?]

Refer to the most recent command containing str. The trailing '?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

so in your case it's

!?reload?:p

that is, you need a trailing ? after the search string.

Your Answer

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