I am attempting to write a script for GeekTool that will show my last X (20) commands on my screen.

I can either display a file or use the output of a shell command (preferred).

The problem is that when I run the command from a script I get ~/bin/update_history_file.sh:fc:5: no such event: 0 as an error.

My script file is:

#!/bin/zsh --login
#history | tail -n 25 > /tmp/history.txt

export HISTFILE=~/.zsh_history 
fc -l -20 -1

The fc command works if I run it from a shell; however if I run it from the script then it fails. I think it has something to do with it not being able to read the history file, but have no confirmation of this.

I can not directly use the .zsh_history file as I use ZSH extended history and has embedded meta data.

1 Answer 1


You should add a fc -R to force reading the history file, and delete that -1

#!/bin/zsh --login
#history | tail -n 25 > /tmp/history.txt

export HISTFILE=~/.zsh_history 
fc -R
fc -l -20
  • This was the exact problem... it wasn't clear to me that it must happen in two separate commands. Thanks! Jan 9, 2013 at 22:32
  • In case anyone else gets fc -R: invalid option, make sure your shebang line is /bin/zsh and not bash or sh.
    – Joe
    Jan 13, 2017 at 8:03

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.