在 OS X 中使用 sed 将文本行添加到 Firefox prefs 文件
我需要阻止 750 台 Mac 更新 Firefox,但保留个人偏好。 因此我必须在文件中插入一行。
使用带有 sed 的 shell 脚本,我很难识别要遵循的行,因为它有特殊字符:
sed '/user_pref("accessibility.typeaheadfind.flashbar", 0); /a\
user_pref("app.update.enabled", false);\'$'\n' /Users/username/pathToFile/prefs.js
显然现在这是打印到屏幕,但稍后会写到文件中。任何帮助表示赞赏。
源文件如下所示:
# Mozilla User Preferences
/* Do not edit this file.
*
* If you make changes to this file while the application is running,
* the changes will be overwritten when the application exits.
*
* To make a manual change to preferences, you can visit the URL about:config
* For more information, see http://www.mozilla.org/unix/customizing.html#prefs
*/
user_pref("accessibility.typeaheadfind.flashBar", 0);
user_pref("app.update.lastUpdateTime.addon-background-update-timer", 1298297884);
user_pref("app.update.lastUpdateTime.background-update-timer", 1298282703);
我需要将 sed 命令中预先提到的代码行作为新行插入到“user_pref”的第一个实例之后,因此,如果我是对的,则 $ 和 \n 可以实现此目的。
看起来代码是正确的并且应该可以工作,但事实并非如此。我在 OS 10.6.8 上使用 bash shell。
I need to prevent 750 Macs from updating Firefox, but retain individuals preferences.
Therefore I must insert a line into a file.
Using a shell script with sed, I am struggling with identifying the line to follow, as it has special characters:
sed '/user_pref("accessibility.typeaheadfind.flashbar", 0); /a\
user_pref("app.update.enabled", false);\'
Obviously for now this is printing to screen, but will write out to a file later on. Any help appreciated.
The source file looks like:
# Mozilla User Preferences
/* Do not edit this file.
*
* If you make changes to this file while the application is running,
* the changes will be overwritten when the application exits.
*
* To make a manual change to preferences, you can visit the URL about:config
* For more information, see http://www.mozilla.org/unix/customizing.html#prefs
*/
user_pref("accessibility.typeaheadfind.flashBar", 0);
user_pref("app.update.lastUpdateTime.addon-background-update-timer", 1298297884);
user_pref("app.update.lastUpdateTime.background-update-timer", 1298282703);
I need to insert the line of code pre-mentioned within the sed command as a new line after the first instance of the "user_pref", so the dollar and \n achieve this, if I'm right.
It looks like the code is right and it should work, but doesn't. I'm using the bash shell on OS 10.6.8.
\n' /Users/username/pathToFile/prefs.js
Obviously for now this is printing to screen, but will write out to a file later on. Any help appreciated.
The source file looks like:
I need to insert the line of code pre-mentioned within the sed command as a new line after the first instance of the "user_pref", so the dollar and \n achieve this, if I'm right.
It looks like the code is right and it should work, but doesn't. I'm using the bash shell on OS 10.6.8.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我自己解决了这个问题。愚蠢的打字错误:
将上面的内容与原始帖子进行比较,您会发现最后的正斜杠需要紧接在分号之后。
对于那些感兴趣的人,我实际上决定:
然后您将“prefs.js”文件替换为您生成的新文件,现在您已经成功地阻止了 Firefox 浏览器提示用户进行更新。
OK, I fixed this myself. Stupid typo:
Compare the above with the original posting and you will notice at the end that the forward slash needed to come right after the semi-colon.
For those interested, I actually settled upon:
You then follow up with replacing the "prefs.js" file with the new one you generated and you have now managed to prevent the Firefox browser from prompting users with an update.