我想在文件名为 build.gradle 中插入一个代码块,这是行块:
signingConfigs {
release {
storeFile file("$keystorefile")
storePassword "$keystorepass"
keyAlias "$keystorealias"
keyPassword "$keystorepass"
}
}
我想将它插入单词“compileSdkVersion”后面我尝试过这个命令:
sed -i '/compileSdkVersion/i \
signingConfigs {\
release {\
storeFile file("$keystorefile")\
storePassword "$keystorepass"\
keyAlias "$keystorealias"\
keyPassword "$keystorepass"\
}\
}\' app/build.gradle
它能够将代码块插入到文件中,但不知何故,行末尾有 \。
signingConfigs {\
release {\
storeFile file("$keystorefile")\
storePassword "$keystorepass"\
keyAlias "$keystorealias"\
keyPassword "$keystorepass"\
}\
}
我想删除行末的 \。如何将这些代码块巧妙地插入到文件中?
答案1
天哪,我错过了最后的 \,现在它解决了,如下所示:
sed -i '/compileSdkVersion/i \
signingConfigs {\
release {\
storeFile file("$keystorefile")\
storePassword "$keystorepass"\
keyAlias "$keystorealias"\
keyPassword "$keystorepass"\
}\
}\ \ ' app/build.gradle