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

发布于 2024-12-04 20:38:35 字数 1070 浏览 0 评论 0原文

我需要阻止 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

并安 2024-12-11 20:38:35

好的,我自己解决了这个问题。愚蠢的打字错误:

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);\'

然后您将“prefs.js”文件替换为您生成的新文件,现在您已经成功地阻止了 Firefox 浏览器提示用户进行更新。

\n' /Users/"$useris"/Library/Application\ Support/Firefox/"$firefoxPath"/prefs.js > /Users/"$useris"/Library/Application\ Support/Firefox/"$firefoxPath"/prefs.txt

然后您将“prefs.js”文件替换为您生成的新文件,现在您已经成功地阻止了 Firefox 浏览器提示用户进行更新。

OK, I fixed this myself. Stupid typo:

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

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:

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);\'

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.

\n' /Users/"$useris"/Library/Application\ Support/Firefox/"$firefoxPath"/prefs.js > /Users/"$useris"/Library/Application\ Support/Firefox/"$firefoxPath"/prefs.txt

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文