Search code examples
zsh

Zsh - The stdout with append (>>) doesn't create a new file, like bash does


In bash when I have an empty directory and type echo "bar" >> foo.txt, it creates a file without problem, when I try the same on zsh, I receive an error of "file doesn't exist"

MacOS (Darwin Kernel Version 22.4.0)

zsh 5.9 (x86_64-apple-darwin22.0)

zimfw installed on iTerm2


Solution

  • As it says on the zsh docummentation

    (>> word) Open file word for writing in append mode as standard output. If the file does not exist, and the CLOBBER and APPEND_CREATE options are both unset, this causes an error; otherwise, the file is created.

    My problem was the clobber and the append_create, so just adding to the ~/.zshrc the setopt clobber and setopt append_create solved the case for MacOS, with zimfw installed