0

I have a pretty strange problem with sed, if I do with this:

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

it's fine. But if I try the following:

[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

also tried to quote the variable:

[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

couldn't figure out where went wrong, please advise.

Shell's version is 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 に答える