* A bug on cat command for zsh
@ 2023-12-04 7:01 Wang, Yichao
2023-12-04 8:01 ` Andreas Kähäri
0 siblings, 1 reply; 3+ messages in thread
From: Wang, Yichao @ 2023-12-04 7:01 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 457 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 1149 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A bug on cat command for zsh
2023-12-04 7:01 A bug on cat command for zsh Wang, Yichao
@ 2023-12-04 8:01 ` Andreas Kähäri
2023-12-04 8:30 ` Wang, Yichao
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Kähäri @ 2023-12-04 8:01 UTC (permalink / raw)
To: Wang, Yichao; +Cc: zsh-workers
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
.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A bug on cat command for zsh
2023-12-04 8:01 ` Andreas Kähäri
@ 2023-12-04 8:30 ` Wang, Yichao
0 siblings, 0 replies; 3+ messages in thread
From: Wang, Yichao @ 2023-12-04 8:30 UTC (permalink / raw)
To: Andreas Kähäri; +Cc: zsh-workers
Hi Andreas,
Thanks for pointing that out.
Yep, I see such different behavior (just by chance when playing around with command line) from MacOS(which is BSD system) and Linux (which follows GNU). I think you’re right they have different implementations of `cat`.
Have a nice day!
> On Dec 4, 2023, at 12:01 AM, Andreas Kähäri <andreas.kahari@abc.se> wrote:
>
> 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
>
> .
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-04 8:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 7:01 A bug on cat command for zsh Wang, Yichao
2023-12-04 8:01 ` Andreas Kähäri
2023-12-04 8:30 ` Wang, Yichao
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).