Skip to content

fix: Bash install script has CRLF line endings, fails on macOS/Linux #1

Description

@willfalalikuo-hub

⏺ ## Bug Description

install-safe-rm.sh 发布文件使用 CRLF (\r\n) 换行符,导致在 macOS/Linux 上执行失败:

/tmp/install-safe-rm.sh: line 10: : command not found
/tmp/install-safe-rm.sh: line 11: set: - invalid option
/tmp/install-safe-rm.sh: line 24: syntax error near unexpected token `{'

Steps to Reproduce

  1. curl -sSL https://github.com/blueraincoatli/safe-rm-toolkit/releases/latest/download/install-safe-rm.sh -o install-safe-rm.sh
  2. bash install-safe-rm.sh

Root Cause

发布文件使用 \r\n (CRLF) 而非 \n (LF),通过 xxd 确认:

00000000: 2321 2f62 696e 2f62 6173 680d 0a23 2053 #!/bin/bash..# S

Workaround

tr -d '\r' < install-safe-rm.sh > install-safe-rm-fixed.sh
bash install-safe-rm-fixed.sh                                                                                                                                                                                                            
 
Suggested Fix                                                                                                                                                                                                                            
                                                          
1. 添加 .gitattributes 文件强制 shell 脚本使用 LF:                                                                                                                                                                                      
*.sh text eol=lf                                          
2. 或在发布前转换:sed -i 's/\r$//' install-safe-rm.sh                                                                                                                                                                                   
                                                                                                                                                                                                                                         
Additional Issue                                                                                                                                                                                                                         
                                                                                                                                                                                                                                         
macOS 的 trash 脚本中 osascript 语法有误,quoted form of 无法在 -e 单行模式中使用,应改为:                                                                                                                                              
                                                          
osascript -e "tell application \"Finder\" to delete (POSIX file \"$abs_path\")"                                                                                                                                                          
                                                                                                                                                                                                                                         
Environment                                                                                                                                                                                                                              
                                                                                                                                                                                                                                         
- macOS Darwin 25.3.0                                                                                                                                                                                                                    
- Shell: zsh                                              

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions