2012-09-10 60 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