首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >。~/..bash剖面

。~/..bash剖面
EN

Ask Ubuntu用户
提问于 2018-08-01 04:42:58
回答 1查看 629关注 0票数 -1

在执行命令之后

代码语言:javascript
复制
$ cd onos
$ cat << EOF >> ~/.bash_profile
export ONOS_ROOT="`pwd`"
source $ONOS_ROOT/tools/dev/bash_profile
EOF
$ . ~/.bash_profile

我搞错了

代码语言:javascript
复制
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的含量为

代码语言:javascript
复制
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
EN

回答 1

Ask Ubuntu用户

发布于 2018-08-01 06:01:12

.bash_profile的这个编辑是不正确的,因为$ONOS_ROOT变量是由您的<展开的,所以它不是逐字保存的,我认为这正是您想要的:

代码语言:javascript
复制
$ 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行。

我的建议是用这样的方法来代替:

代码语言:javascript
复制
$ cd onos
$ { echo "export ONOS_ROOT=`pwd`";
    echo 'source $ONOS_ROOT/tools/dev/bash_profile'; } >>~/.bash_profile

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

如果您多次运行该命令,它仍然会追加多行。因此,您可能希望添加一个检查,以检查编辑是否已经执行,在这种情况下,您将跳过附加:

代码语言:javascript
复制
$ cd onos
$ grep -qw ONOS_ROOT ~/.bash_profile || {
    echo "export ONOS_ROOT=`pwd`";
    echo 'source $ONOS_ROOT/tools/dev/bash_profile';
  } >>~/.bash_profile

此外,这个命令:

代码语言:javascript
复制
$ . ~/.bash_profile

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

票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1061311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档