Skip to content

Fix setup-template.sh macOS compatibility with cross-platform sed approach#4

Merged
rfay merged 2 commits intomainfrom
copilot/fix-setup-template-script
Oct 8, 2025
Merged

Fix setup-template.sh macOS compatibility with cross-platform sed approach#4
rfay merged 2 commits intomainfrom
copilot/fix-setup-template-script

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 8, 2025

Problem

The setup-template.sh script was failing on macOS with the error:

sed: 1: "README.md
": invalid command code

This occurred because macOS uses BSD sed, which requires an extension argument for the -i (in-place edit) flag, while Linux uses GNU sed where the extension argument is optional. The script was using sed -i "pattern" file, which works on Linux but fails on macOS.

Solution

Replaced all sed -i commands with a cross-platform replace_in_file() function that works on both BSD and GNU sed:

replace_in_file() {
    local file=$1
    local pattern=$2
    local replacement=$3
    sed "s|$pattern|$replacement|g" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
}

This approach:

  • Uses a temporary file instead of in-place editing
  • Works identically on both macOS (BSD sed) and Linux (GNU sed)
  • Maintains all original functionality without requiring OS detection

Changes

  • Added replace_in_file() helper function
  • Replaced 6 sed -i commands with calls to the new function
  • No functional changes to the script behavior

Fixes the issue reported in the original issue where the setup script would fail on macOS systems.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix</issue_title>
<issue_description>@copilot the setup-template.sh fails on macOS with

sed: 1: "README.md
": invalid command code

I imagine this is a result of platform differences with sed. Use awk maybe.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #3

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: rfay <112444+rfay@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix setup-template.sh for macOS compatibility Fix setup-template.sh macOS compatibility with cross-platform sed approach Oct 8, 2025
Copilot AI requested a review from rfay October 8, 2025 17:43
@rfay rfay marked this pull request as ready for review October 8, 2025 17:51
@rfay rfay merged commit 8c486af into main Oct 8, 2025
2 of 4 checks passed
@rfay rfay deleted the copilot/fix-setup-template-script branch October 8, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix

2 participants