我有一个README.md文件,我想用一行代码替换文本标识符{{CODESHIP_CODE}}
- 特别是包含git分支名称的构建状态图像代码片段。
我认为它看起来像这样......
git rev-parse --abbrev-ref HEAD
放在bash变量sed
(可能为grep
)在README.md文件中搜索指定的{{CODESHIP_CODE}}
模式/字符串,并将其替换为构建映像状态代码我写的代码如下:
#!/bin/bash
# Get the current branch
function git_branch {
git rev-parse --abbrev-ref HEAD
}
# Set variable to current branch
branch=$(git_branch)
# Define the pattern to search for
# This pattern/string gets replaced with the build status image code
id="{{CODESHIP_CODE}}"
# Create build status image code
# Inject the $branch variable into the correct location
codeship_build_status="[ ![Codeship Status for ExampleGitHubUser/ExampleRepo](https://codeship.com/projects/a99d9999-9b9f-9999-99aa-999a9a9a9999/status?branch=$branch)](https://codeship.com/projects/999999)"
# Find the pattern to replace
# Then replace it with the build status image
sed -i -e "s/{{CODESHIP_CODE}}/$codeship_build_status/g" README.md
问题是我一直收到以下错误:
sed: 1: "s/{{CODESHIP_CODE}}/[ ! ...": bad flag in substitute command: 'a'
我不确定如何解决此问题,以便脚本正常运行。任何帮助将不胜感激。
答案 0 :(得分:2)
您不能使用包含未转义分隔符的替换字符串。转义字符串中的分隔符,或切换到不同的分隔符。
DECLARE @MyParameter INT
SET @MyParameter = Set At Runtime (could be -1 or any value >=1)
SELECT manyfields
FROM manyjoinedtables
WHERE
@MyParameter <= -1
OR
(
@MyParameter > -1
AND FIELD1 = MyParameter
AND AnotherField = Value
)
确保新的分隔符不包含在字符串中。