Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh blocks at file truncation

On Sep 25, 12:23pm, Marko Vihoma wrote:
} $ > file.txt
} creates a new empty file if it does not exist and complains:
} zsh: file exists: file.txt
} if it exists...

16.2.6 Input/Output

CLOBBER (+C, ksh: +C) <D>
     Allows `>' redirection to truncate existing files, and `>>' to
     create files.  Otherwise `>!' or `>|' must be used to truncate a
     file, and `>>!' or `>>|' to create a file.

} I must have something setup in my ~/.zshrc for this to work that way

You have not.  NO_CLOBBER (+C) is the default, so setup is needed to
make it NOT work that way.

} And if I pull what i wrote
} from history it will give me
} $ >| file.txt

That's a convenience feature.  The assumption is that if you failed to
create the file because of NO_CLOBBER, but then you go to the trouble
of recalling the history and trying it again, you probably really meant
to clobber the file, so the history fixes that part for you in advance.

This all derives from zsh's distant past as a shell for college students
who had a tendency to accidentally destroy their homework.  Zsh's special
default treatment of "rm *" can be traced to the same thing.  (And I'm
only partly kidding here.)

Messages sorted by: Reverse Date, Date, Thread, Author