history add of Zsh give no clue

69 Views Asked by At

Bash history -s is to be done equivalent history in Zsh but how come history add of Zsh give no clue

% history add printf "FOO" 
fc: event not found: add

So confusing documentation hint it history add, please really help out.

1

There are 1 best solutions below

0
Daniel On

Ok, it's old, but here is the answer. Found it in Unix & Linux.

You can use print -s or print -S for this:

-s

Place the results in the history list instead of on the standard output. Each argument to the print command is treated as a single word in the history, regardless of its content.

-S

Place the results in the history list instead of on the standard output. In this case only a single argument is allowed; it will be split into words as if it were a full shell command line. The effect is similar to reading the line from a history file with the HIST_LEX_WORDS option active.

See https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html#index-print

Example of how it works:

enter image description here