我一直在关注关于ROS wiki的catkin教程。我遇到了这样的情况:要将工作区添加到ROS环境中,您需要获取生成的安装文件:
$ . ~/catkin_ws/devel/setup.bash我的问题是:这种采购的特殊语法是什么?我们不应该使用源命令吗?据我所知。引用当前目录。提前谢谢。
发布于 2019-04-07 16:34:37
$ 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.$ source ~/.bashother # Valid
$ . ~/.bashother # Valid但是,通常情况下,在获取文件之前,我们会检查文件的存在:
$ [[ -f ~/.bashother ]] && source ~/.bashother我建议您使用source命令而不是.。其主要原因是代码的可读性和可维护性。
通过使用source,您可以更容易、更准确地找到代码库中的位置,或者找到源资源的文件系统,而不是搜索.。如果您正在经历问题,或者需要进行更改,这是非常有用的,特别是当您不是唯一的贡献者时。
如果您想要一种创建资源文件并轻松获取它们的方法,您可以在您的.bashrc文件中设置如下内容:
BASHRCDIR="${HOME}/.bashrc.d"
if [ -d "$BASHRCDIR" ]; then
find $BASHRCDIR/* -executable| while read f;
do
source "${f}"
done
fi然后,将加载~/.bashrc.d/中的任何D10文件。您可以在文件名前加上数字以确保顺序:
source ~/.bashrc # Source updated .bashrc
mkdir ~/.bashrc.d/
touch ~/.bashrc.d/001-bashother
chmod +x ~/.bashrc.d/001-bashothersource不是可执行文件,而是bash命令。zsh确保在使用source时在$PATH之前搜索当前目录。.是在中无效。https://askubuntu.com/questions/1131914
复制相似问题