If you only want to match TAG=
lines starting with as a replacement rule, you can slightly modify sed
the command's replacement expression. Here is the updated example script:
#!/bin/bash
target_value="2.0.0.RELEASE" # 目标值
# 使用sed命令替换以TAG=开头的行中的字符串
sed -i 's/^TAG=.*/TAG='"$target_value"'/g' .env
In the updated replacement expression, we use ^TAG=.*
to match TAG=
lines starting with . This will match any TAG=
line starting with and replace it with TAG=目标值
.
Make sure to replace the filename in the script .env
with the filename you actually use and target_value
set it to your desired target value. After running the script, it will replace the string .env
in the file starting TAG=
with the target value.