Skip to content

setup.sh fails when writing Whisper command path containing slashes #14

@syndicalt

Description

@syndicalt

Problem

Running ./setup.sh --build on Linux can fail during local Whisper setup after openai-whisper is installed:

Unknown regexp modifier "/b" at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

Reproduction

On Linux, run:

./setup.sh --build

The script configures local Whisper and attempts to write this value into .env:

WHISPER_COMMAND=.venv-whisper/bin/whisper

Root cause

setup.sh currently updates existing .env keys with this Perl substitution:

perl -0pi -e "s/^${key}=.*\$/${key}=${value}/m" .env

When value contains /, such as .venv-whisper/bin/whisper, the slash is interpreted as the Perl substitution delimiter. The /b in /bin is then parsed as an invalid regexp modifier, causing the setup script to abort.

This is not machine-specific; any value containing unescaped / can trigger it.

Suggested fix

Avoid embedding unescaped values directly into a Perl substitution. For example, replace the existing-key path in upsert_env with a delimiter-safe/plain-text update using awk:

upsert_env() {
  local key="$1"
  local value="$2"
  local tmp_file

  if grep -q "^${key}=" .env 2>/dev/null; then
    tmp_file=$(mktemp ".env.tmp.XXXXXX")
    awk -v key="$key" -v value="$value" '
      $0 ~ "^" key "=" {
        print key "=" value
        next
      }
      { print }
    ' .env > "$tmp_file"
    mv "$tmp_file" .env
  else
    printf "%s=%s\n" "$key" "$value" >> .env
  fi
}

I verified the original failure with a minimal reproduction using WHISPER_COMMAND=.venv-whisper/bin/whisper, and the awk approach writes the expected line without the Perl parsing error.

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