首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >采购设置.*sh文件catkin

采购设置.*sh文件catkin
EN

Ask Ubuntu用户
提问于 2019-04-07 16:08:10
回答 1查看 707关注 0票数 -1

我一直在关注关于ROS wiki的catkin教程。我遇到了这样的情况:要将工作区添加到ROS环境中,您需要获取生成的安装文件:

代码语言:javascript
复制
$ . ~/catkin_ws/devel/setup.bash

我的问题是:这种采购的特殊语法是什么?我们不应该使用源命令吗?据我所知。引用当前目录。提前谢谢。

EN

回答 1

Ask Ubuntu用户

发布于 2019-04-07 16:34:37

代码语言:javascript
复制
$ source
bash: source: filename argument required
source: usage: source filename [arguments]

$ help source
source: source filename [arguments]
    Execute commands from a file in the current shell.

    Read and execute commands from FILENAME in the current shell.  The
    entries in $PATH are used to find the directory containing FILENAME.
    If any ARGUMENTS are supplied, they become the positional parameters
    when FILENAME is executed.

    Exit Status:
    Returns the status of the last command executed in FILENAME; fails if
    FILENAME cannot be read.
代码语言:javascript
复制
$ source ~/.bashother    # Valid
$ . ~/.bashother         # Valid

但是,通常情况下,在获取文件之前,我们会检查文件的存在:

代码语言:javascript
复制
$ [[ -f ~/.bashother ]] && source ~/.bashother

我建议您使用source命令而不是.。其主要原因是代码的可读性和可维护性。

通过使用source,您可以更容易、更准确地找到代码库中的位置,或者找到源资源的文件系统,而不是搜索.。如果您正在经历问题,或者需要进行更改,这是非常有用的,特别是当您不是唯一的贡献者时。

如果您想要一种创建资源文件并轻松获取它们的方法,您可以在您的.bashrc文件中设置如下内容:

代码语言:javascript
复制
BASHRCDIR="${HOME}/.bashrc.d"
if [ -d "$BASHRCDIR" ]; then
    find $BASHRCDIR/* -executable| while read f;
    do
        source "${f}"
    done
fi

然后,将加载~/.bashrc.d/中的任何D10文件。您可以在文件名前加上数字以确保顺序:

代码语言:javascript
复制
source ~/.bashrc # Source updated .bashrc
mkdir ~/.bashrc.d/
touch ~/.bashrc.d/001-bashother
chmod +x ~/.bashrc.d/001-bashother
  • source不是可执行文件,而是bash命令。
  • zsh确保在使用source时在$PATH之前搜索当前目录。
  • .在中无效
票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1131914

复制
相关文章

相似问题

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