当我使用 时,我在 MAC OS X 上遇到错误sed
,如下所示:
sed -i '' '/user_pref("mail.identity.id1.reply_on_top", 1);/ a\
user_pref("mail.identity.id1.sig_file", "/Users/nicolas.hulot/Library/Mail/V2/MailData/Signatures/signature.html");
user_pref("mail.identity.id1.sig_file-rel", "[ProfD]../../../Mail/V2/MailData/Signatures/signature.html");
' ~/Library/Thunderbird/Profiles/*.default/prefs.js
当我用另一个字符串更改第二行和第三行时,'abcdefgh...'
这很好,但是对于这个有很多特殊字符的字符串,那就太错误了。
出现的错误是:
sed: 3: "/user_pref("mail.identi ...": invalid command code u
答案1
fornewline
的pend 会破坏它,因此您必须使用反斜杠sed
或用符号替换:a
newline
\n
sed -i '' '/user_pref("mail.identity.id1.reply_on_top", 1);/ a\
user_pref("mail.identity.id1.sig_file", "/Users/illias.seba/Library/Mail/V2/MailData/Signatures/signature.html");\
user_pref("mail.identity.id1.sig_file-rel", "[ProfD]../../../Mail/V2/MailData/Signatures/signature.html");\
' ~/Library/Thunderbird/Profiles/*.default/prefs.js
或者
sed -i '' '/user_pref("mail.identity.id1.reply_on_top", 1);/ a\
user_pref("mail.identity.id1.sig_file", "/Users/illias.seba/Library/Mail/V2/MailData/Signatures/signature.html");\nuser_pref("mail.identity.id1.sig_file-rel", "[ProfD]../../../Mail/V2/MailData/Signatures/signature.html");\n' ~/Library/Thunderbird/Profiles/*.default/prefs.js