Unable to use sed properly in the script step


Can anybody explain the reason why my sed commands I am issuing in the script step is failing?

I am trying to replace the git_url value in a matchfile and the value being replaced has a slash. I thought this is the problem so I ended up with the following statement to escape the slash character:

        sed -i "s/^git_url.*$/git_url \"${CERT_REPO_URL//\//\\/}\"/g"  $FASTLANE_WORK_DIR/Matchfile

The statement works in my linux box and FASTLANE_WORK_DIR is indeed visible in the step so the target file resolves to “fastlane/Matchfile”. However the execution fails with:

sed: 1: “fastlane/Matchfile”: invalid command code f

I thought it was the slashes so I resorted to the workaround of deleting all git_url lines and then appending the correct one at the end. The sed delete command still fail.

sed -i “/^git_url.*/d” Matchfile

sed: 1: “Matchfile”: invalid command code M

Based on the error it looks like the target file is being seen as part of the sed instruction. I already tried escaping the double quotes but it didnt change the result.




Hi @anuerind!

Have you tried using our Change value in file to accomplish this?

Anyhow, in case the issue is still present please send us a build URL here too so we can look into it a bit deeper!



I havent but I will try it out for basic replacements. I was building a small replication suite as sed is a pretty common and multi-purpose tool. From what I can see the parameters are being reorganized such that the target file path becomes the instruction to sed which is not the intended use.

Script step contents:

#!/usr/bin/env bash
set -x

ls -l
tree .

echo Cloned copy of Fastfile
head -2 `pwd`/testing_ground/fastlane/Fastfile

sed -i "s/^REQUIRED_XCODE_VERSION.*freeze/REQUIRED_XCODE_VERSION = '11.1'.freeze/g" `pwd`/testing_ground/fastlane/Fastfile

echo after replacement
head -2 `pwd`/testing_ground/fastlane/Fastfile

The fastlane/Fastfile only contains the following lines and the intent is to change teh value from 11.5 to 11.1. This is a simplified test case to replicate the error.

$ cat fastlane/Fastfile 
default_platform :ios


Sample execution: https://app.bitrise.io/build/72af9269c7f858e7