why does rg '<,'> file.txt
clear the contents of file.txt
?
#2888
-
Please tick this box to confirm you have reviewed the above.
What version of ripgrep are you using?ripgrep 14.1.1 features:+pcre2 PCRE2 10.43 is available (JIT is available) How did you install ripgrep?Homebrew What operating system are you using ripgrep on?MacOS 14.6.1 Describe your bug.ripgrep clears the entire content of the file or will replace the file with random garbage. What are the steps to reproduce the behavior?You will see that the file is completely cleared after issuing the command. I would be careful debugging this problem as it might result in data lost.
What is the actual behavior?
What is the expected behavior?I ended up running the command trying to see if I can pass through selected content in vim to ripgrep. I wasn't too worried but imagine my surprise when something I did cleared the file I was searching. I narrowed it down to this command. The expected behaviour is no matches and the file isn't touched. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is a shell command typo that ripgrep can't do anything about. The shell interprets the quoting and redirect syntax before ripgrep is even executed, all it knows is that you've told it to search for the pattern If you want, you can enable the
If you do this you will have to remember to use |
Beta Was this translation helpful? Give feedback.
This is a shell command typo that ripgrep can't do anything about. The shell interprets the quoting and redirect syntax before ripgrep is even executed, all it knows is that you've told it to search for the pattern
<,
and output the results to a file. Even if it could see the raw shell command, it's perfectly valid, so there's no way for it (or the shell) to figure out that you meant to type something elseIf you want, you can enable the
noclobber
option in your shell profile to make it so that>
isn't allowed to overwrite the contents of existing files: