0

如果我这样做,我有一个非常奇怪的问题sed

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

没关系。但是,如果我尝试以下操作:

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

还尝试引用变量:

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

不知道哪里出错了,请指教。

Shell 的版本是3.2.25(1)-release.

4

1 回答 1

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"
于 2012-09-10T08:00:39.080 回答