加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

源脚本中的.bashrc无法正常工作

发布时间:2020-12-15 22:15:34 所属栏目:安全 来源:网络整理
导读:我正在做一个安装ros的脚本,在安装它之后,使用catkin_make编译工作区. 我找到了解决问题的解决方案,但我无法解释原因.我有一个名为install.bash的文件正在调用其他人: #!/bin/bashsource 01_install_ros.bash 重要的是01_install_ros.bash: # variable not
我正在做一个安装ros的脚本,在安装它之后,使用catkin_make编译工作区.

我找到了解决问题的解决方案,但我无法解释原因.我有一个名为install.bash的文件正在调用其他人:

#!/bin/bash

source 01_install_ros.bash

重要的是01_install_ros.bash:

# variable not set because it is done in the script setup.bash of ros
echo "before source in 01_install_ros"
echo "ROS_ROOT: "$ROS_ROOT
whereis catkin_make
echo ""

echo "source /opt/ros/kinetic/setup.bash" >> $HOME/.bashrc
# doesn't set the variables
source "$HOME"/.bashrc
# the solutions
source /opt/ros/kinetic/setup.bash

# variables not set if I use the source of .bashrc
echo "after source in 01_install_ros"
echo "ROS_ROOT: "$ROS_ROOT
whereis catkin_make
echo ""

正如在评论中所写,采购.bashrc而不是直接setup.bash不起作用.我真的不明白为什么.你能解释一下吗?

解决方法

某些平台附带了一个?/ .bashrc,如果发现shell是非交互式的,则顶部有条件显式停止处理.

如果是这种情况,从脚本中获取?/ .bashrc将不起作用,因为默认情况下脚本在非交互式shell中运行.

你的选择是:

>或者:在?/ .bashrc中停用条件
>或者:在调用source~ / .bashrc之前尝试模拟交互式shell.
所需的具体模拟取决于条件的具体情况,但有两种可能的方法;如果您事先不知道您将遇到哪些条件,您可能必须同时使用它们:

> set -i暂时使$ – 包含i,表示交互式shell.
>确保环境变量PS1具有值.

或者,如果您控制自己的脚本的调用方式,则可以使用bash -i脚本调用它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读