.~/.bash_profile

.~/.bash_profile

执行命令后

$ cd onos
$ cat << EOF >> ~/.bash_profile
export ONOS_ROOT="`pwd`"
source $ONOS_ROOT/tools/dev/bash_profile
EOF
$ . ~/.bash_profile

我收到错误

bash: /tools/dev/bash_profile: No such file or directory
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: /tools/dev/bash_profile: No such file or directory
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: source: /bin/pwd: cannot execute binary file

~/.bash_profile 的内容是

export ONOS_ROOT="pwd"
source /tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source /tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source  pwd /tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile

答案1

对您的编辑.bash_profile是不正确的,因为$ONOS_ROOT变量是由您的此处文档(<<EOF)扩展的,所以它没有被逐字保留,我相信这是您想要的:

$ cd onos
$ cat << EOF >> ~/.bash_profile
export ONOS_ROOT="`pwd`"
source $ONOS_ROOT/tools/dev/bash_profile
EOF

该变量很可能是空的,因此它会扩展为无,这解释了运行此命令后source /tools/dev/bash_profile您的行。.bash_profile

我的建议是使用类似这样的方法:

$ cd onos
$ { echo "export ONOS_ROOT=`pwd`";
    echo 'source $ONOS_ROOT/tools/dev/bash_profile'; } >>~/.bash_profile

它使用两个单独的回显,第一个使用双引号来扩展pwd命令输出,第二个使用单引号来防止扩展$ONOS_ROOT要保留的变量引用。

如果重复运行此命令,它仍会多次附加行。因此,也许您想添加一个检查来检查编辑是否已执行,在这种情况下,您将跳过附加操作:

$ cd onos
$ grep -qw ONOS_ROOT ~/.bash_profile || {
    echo "export ONOS_ROOT=`pwd`";
    echo 'source $ONOS_ROOT/tools/dev/bash_profile';
  } >>~/.bash_profile

另外,这个命令:

$ . ~/.bash_profile

它也可能导致问题,因为.bash_profile通常应该只获取一次...您$PATH至少可能会在您的帐户中出现虚假的重复条目,这可能会导致意外的问题...最好的是注销并再次登录,或启动一个新的终端会话(假设您的终端产生登录shell)以使这些新设置生效。

相关内容