在bash脚本源文件。 [英] Source files in a bash script.

查看:103
本文介绍了在bash脚本源文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用彼此相邻ROS的两个版本。使用一个我要采购一些环境变量的特定版本。我想创建一个脚本,做到这一点。
但是,如果我创建一个脚本像下面的变量都没有设置,他们很可能在子shell设置。我如何可以将文件源到主终端的壳呢?

source.sh

 源/opt/ros/fuerte/setup.bash;
源〜/ fuerte_workspace / setup.bash;


解决方案

执行Shell脚本使用。 ./(点空间点斜杠)

在使用点空间点斜杠,如下图所示,将执行在当前shell脚本但不分叉一个子壳执行shell脚本。

  $。 ./setup.bash

在换句话说,这执行在当前shell中的 setup.bash 指定的命令,和prepares环境适合你。

I am using two versions of ROS next to each other. To use one I have to source some enviroment variables for the specific version. I would like to create a script that does this. But if I create a script like below the variables are not set, they are probably set in a subshell. How can I source the files to the main terminal shell?

source.sh

source /opt/ros/fuerte/setup.bash;
source  ~/fuerte_workspace/setup.bash;

解决方案

Execute Shell Script Using . ./ (dot space dot slash)

While executing the shell script using "dot space dot slash", as shown below, it will execute the script in the current shell without forking a sub shell.

$ . ./setup.bash

In other words, this executes the commands specified in the setup.bash in the current shell, and prepares the environment for you.

这篇关于在bash脚本源文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆