Skip to content

rename_app.sh script is not compatible with Linux (GNU sed) #9

@dongfengweixiao

Description

@dongfengweixiao

Description

The rename_app.sh script uses macOS/BSD sed syntax (sed -i ''), which causes it to fail on Linux systems that use GNU sed. When attempting to run the script on Linux, all sed commands fail with "No such file or directory" errors.

Environment

  • OS: Linux (Arch Linux, kernel 6.17.3-arch2-1-lily)
  • Shell: bash
  • sed: GNU sed

Steps to Reproduce

  1. Clone the repository on a Linux system
  2. Run the rename script:
    ./rename_app.sh --app-name "something" --package-name "io.github.something"
  3. Confirm with y when prompted

Expected Behavior

The script should successfully rename the app and update package names across all platform files.

Actual Behavior

All sed commands fail with errors like:
sed: cannot read s/.*</string>/substurgeon</string>/g: No such file or directory

Root Cause

The script uses BSD sed syntax (sed -i '') which is specific to macOS. On Linux, GNU sed expects:

  • BSD sed (macOS): sed -i '' 's/pattern/replacement/g' file
  • GNU sed (Linux): sed -i 's/pattern/replacement/g' file

When GNU sed encounters sed -i '', it interprets '' as a filename argument instead of an empty backup extension, causing the "No such file or directory" error.

Suggested Fix

Make the script cross-platform compatible by detecting the OS and using the appropriate sed syntax:

# Detect OS and set appropriate sed command
if [[ "$OSTYPE" == "darwin"* ]]; then
  # macOS/BSD
  alias sed_i='sed -i ""'
else
  # Linux/GNU
  alias sed_i='sed -i'
fi

Or replace all occurrences of sed -i '' with sed -i (Linux-compatible) as a temporary fix for Linux users.

Additional Context

This is a common portability issue between macOS and Linux scripts. Using the OSTYPE variable to detect the platform allows the script to work on both systems seamlessly.

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