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

Re: A bug on cat command for zsh



On Mon, Dec 04, 2023 at 07:01:42AM +0000, Wang, Yichao wrote:
> Hi there,
> 
> I am using zsh 5.9 (x86_64-apple-darwin23.0) on MacOS.
> 
> The following command in zsh will cause severe damage by running forever into a dead loop.
> - when you accidentally mess up the redirection flows
> 
> ```bash
> touch 1.txt
> echo "anything" > 1.txt
> cat < 1.txt >> 1.txt
> ```
> 
> However, on Linux bash, this behavior is prohibited and hinted.
> 
> ```bash
> cat < 1.txt >> 1.txt
> cat: -: input file is output file
> ```
> 
> Best,
> Unknown name

Allowing the programmer to shoot themselves in the foot does not
seem like a bug to me.  Note that bash release 5.2.15 does not
seem to babysit the user in the way that you describe by default.
Rather, it's the coreutils implementation of cat that does this.

You may have two implementaions of cat on your system (it's possibly
a BSD system, or at least non-GNU system, with coreutils installed
alongside the native utilities).  Check with "type cat" in both shells
to see what cat is being picked up.


-- 
Andreas (Kusalananda) Kähäri
Uppsala, Sweden

.




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