2012-09-10 32 views
0

我有一个非常奇怪的问题sed,如果我做这个:SED无法处理用户的〜/ .bash_profile中

[[email protected] ~]-> sed -i 's/TLRAGENT_IP=.*/TLRAGENT_IP='"${HOST_IP}"'/' ~user/.bash_profile 

它的罚款。但是,如果我尝试以下方法:

[[email protected] ~]-> CONF_FILE="~user/.bash_profile" 
[[email protected] ~]-> sed -i 's/TLRAGENT_IP=.*/TLRAGENT_IP='"${HOST_IP}"'/' ${CONF_FILE} 
sed: can't read ~user/.bash_profile: No such file or directory 

也试图引用变量:

[[email protected] ~]-> sed -i 's/TLRAGENT_IP=.*/TLRAGENT_IP='"${HOST_IP}"'/' "${CONF_FILE}" 
sed: can't read ~user/.bash_profile: No such file or directory 

想不出哪里出了问题,请指教。

壳牌的版本是3.2.25(1)-release

回答

1

man bash/EXPANSION

EXPANSION 
Expansion is performed on the command line after it has been 
split into words. There are seven kinds of expansion per- 
formed: brace expansion, tilde expansion, parameter and 
variable expansion, command substitution, arithmetic expan- 
sion, word splitting, and pathname expansion. 

The order of expansions is: brace expansion, tilde expan- 
sion, parameter, variable and arithmetic expansion and com- 
mand substitution (done in a left-to-right fashion), word 
splitting, and pathname expansion. 

的参数和变量扩展来自波浪线扩展后

要具有波浪线扩展,这可以在变量定义来完成的

CONF_FILE=~user/.bash_profile 

代替

CONF_FILE="~user/.bash_profile" 
+0

谢谢,这很快。 – leafei