sed引用shell变量

发表于:2007-05-26来源:作者:点击数: 标签:
sed引用shell变量必须使用双引号,而sed一般使用单引号,下面的例子是给/etc/X11/xorg.conf中增加字体路径/usr/share/fonts/ttf/zh_CN:
#!/bin/sh

# 查找最后一行FontPath的行数
LINENO=`sed -n '/FontPath/=' /etc/X11/xorg.conf | sed -n '$p'`

# 在最后一行FontPath之后附加字体路径/usr/share/fonts/ttf/zh_CN
sed "${LINENO}a\        FontPath     \"/usr/share/fonts/ttf/zh_CN/\"" /etc/X11/xorg.conf >
/etc/X11/xorg.conf.bak

mv /etc/X11/xorg.conf.bak /etc/X11/xorg.conf


原文转自:http://www.ltesting.net