windows-safe-grep
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWindows-Safe Grep Skill
Windows安全Grep技能
Problem
问题
On Windows, paths containing backslash-space sequences (e.g., ) can cause ripgrep to fail because:
D:\Projects\Vibe Code\isometricid- The in
\nis interpreted as a newline characterisometricid - Combined with the following , this creates a reference to the reserved Windows device name
ulnul - Error:
rg: D:\Projects\Vibe Code\isometricid\nul: Incorrect function. (os error 1)
在Windows系统中,包含反斜杠-空格序列的路径(如 )会导致ripgrep运行失败,原因如下:
D:\Projects\Vibe Code\isometricid- 中的
isometricid会被解释为换行符\n - 后续的 与之结合后,会被识别为Windows系统保留的设备名
ulnul - 报错信息:
rg: D:\Projects\Vibe Code\isometricid\nul: Incorrect function. (os error 1)
Solution
解决方案
Use bash commands with proper path quoting to work around this Windows-specific issue:
使用带正确路径引号的Bash命令来规避这个Windows特有的问题:
Safe Grep Command Pattern
安全Grep命令模板
bash
rg --fixed-strings "SEARCH_TERM" "/d/Projects/Vibe Code/isometricid"Or use forward slashes and proper quoting:
bash
rg --fixed-strings "SEARCH_TERM" "$(cygpath -u "D:\Projects\Vibe Code\isometricid")"bash
rg --fixed-strings "SEARCH_TERM" "/d/Projects/Vibe Code/isometricid"或者使用正斜杠并添加正确引号:
bash
rg --fixed-strings "SEARCH_TERM" "$(cygpath -u "D:\Projects\Vibe Code\isometricid")"Alternative: Use find + grep
替代方案:使用find + grep
bash
find "/d/Projects/Vibe Code/isometricid" -type f \( -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.jsx" \) -exec grep -H --line-number "SEARCH_TERM" {} \;bash
find "/d/Projects/Vibe Code/isometricid" -type f \( -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.jsx" \) -exec grep -H --line-number "SEARCH_TERM" {} \;Usage
使用方法
When grep fails with "Incorrect function (os error 1)" on Windows:
- Use this skill
- Replace the path with forward slashes: →
D:\Projects\Vibe Code\isometricid/d/Projects/Vibe Code/isometricid - Or use the bash command pattern with proper quoting
当在Windows上执行grep出现"Incorrect function (os error 1)"错误时:
- 采用本技能提供的方法
- 将路径替换为正斜杠格式:→
D:\Projects\Vibe Code\isometricid/d/Projects/Vibe Code/isometricid - 或者使用带正确引号的Bash命令模板
Example
示例
bash
rg --fixed-strings "polar_product_id" "/d/Projects/Vibe Code/isometricid/src"bash
rg --fixed-strings "polar_product_id" "/d/Projects/Vibe Code/isometricid/src"