首页 > 解决方案 > 使用 sed 命令添加 debian 存储库

问题描述

我想通过配置自动生成我的 debian 系统 virtualbox。我必须安装非标准或默认的 PHP 环境。我必须添加存储库 dotdeb以查找 5.3 版本的特殊包 PHP。

我的 shell 配置脚本必须编辑 /etc/apt/sources.list 以添加与 dotdeb 存储库对应的行。这一行是:

deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all

如何使用 sed 命令编辑我的文件以获得以下结果

#

# deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main

#deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main

deb http://httpredir.debian.org/debian wheezy main
deb-src http://httpredir.debian.org/debian wheezy main

deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main

deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all

/etc/apt/sources.list 的默认内容文件是:

#

# deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main

#deb cdrom:[Debian GNU/Linux 7.11.0 _Wheezy_ - Official amd64 NETINST Binary-1 20160605-17:36]/ wheezy main

deb http://httpredir.debian.org/debian wheezy main
deb-src http://httpredir.debian.org/debian wheezy main

deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main

最后,我只想在文件末尾添加一个空行,然后添加到特定行。但是我没有找到如何在文件末尾添加空行并使用 sed 命令添加具有多个特殊字符的特定行...

标签: seddebian

解决方案


sed -i '$ a\\ndeb http://packages.dotdeb.org wheezy all\ndeb-src http://packages.dotdeb.org wheezy all' /etc/apt/sources.list

推荐阅读