繁体   English   中英

在OS X中使用sed将文本行添加到firefox prefs文件

[英]Use sed to add line of text to firefox prefs file in OS X

我需要阻止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。

好的,我自己修复了这个问题。 愚蠢的错字:

sed '/user_pref("accessibility.typeaheadfind.flashbar", 0);/ a\

将以上内容与原始过帐进行比较,最后您会发现,需要在分号后立即加上正斜线。

对于那些感兴趣的人,我实际上选择了:

useris=$(who | grep -v support | awk '{print $1}' | awk "NR==1{print;exit}")
firefoxPath=$(grep "Path=" /Users/"$useris"/Library/Application\ Support/Firefox/profiles.ini | awk -F '=' '{print $2}')

sed '/^user_pref("app.update.lastUpdateTime/ i\
user_pref("app.update.enabled", false);\'$'\n' /Users/"$useris"/Library/Application\ Support/Firefox/"$firefoxPath"/prefs.js > /Users/"$useris"/Library/Application\ Support/Firefox/"$firefoxPath"/prefs.txt

然后,您继续进行操作,将“ prefs.js”文件替换为所生成的新文件,并且现在您已设法阻止Firefox浏览器提示用户更新。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM