我正尝试将[PROJECT_ID]
之类的方括号文本替换为and env var PROJECT_ID
...我尝试过:
export PROJECT_ID=adfaf@asdf.com
echo "[PROJECT_ID]" >> test.text
sed -i -e 's|[PROJECT_ID]|$PROJECT_ID|g' test.text
我明白了:
[$PROJECT_ID$PROJECT_ID$PROJECT_ID$PROJECT_ID$PROJECT_ID$PROJECT_ID$PROJECT_ID$PROJECT_ID$PROJECT_ID$PROJECT_ID]
我尝试了许多不同的方法,但似乎无法使其工作
答案 0 :(得分:0)
's|[PROJECT_ID]|$PROJECT_ID|g'
使用文本字面。但似乎您想扩展$ PROJECT_ID。export
。固定代码(我的猜测):
PROJECT_ID=adfaf@asdf.com
echo "[PROJECT_ID]" > test.text
sed -i -e "s|[PROJECT_ID]|$PROJECT_ID|g" test.text
答案 1 :(得分:0)
您必须使用反斜杠将括号转义以使其在字面上匹配。
PROJECT_ID=adfaf@asdf.com
echo "[PROJECT_ID]" > test.text
sed -i -e "s|\[PROJECT_ID\]|$PROJECT_ID|g" test.text