在执行命令之后
$ 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发布于 2018-08-01 06:01:12
对.bash_profile的这个编辑是不正确的,因为$ONOS_ROOT变量是由您的<展开的,所以它不是逐字保存的,我认为这正是您想要的:
$ 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)以使这些新设置生效。
https://askubuntu.com/questions/1061311
复制相似问题