我正在尝试安装最新的ROS Hydro,因为一切似乎都已下载并配置到正确的位置,所以一切都很好。我想每次使用ros时都会获得一个安装脚本。我尝试时发生了问题:

source setup.sh


发生错误:

bash: /tmp/setup.sh.DPE4BtgiZY: cannot overwrite existing file
bash: [: 0: unary operator expected


我曾尝试以根用户身份运行脚本或使其成为可执行文件,但没有任何效果,并且仍然存在相同的错误。下面是setup.sh

#!/bin/bash
# generated from catkin/cmake/template/setup.sh.in

# Sets various environment variables and sources additional environment hooks.
# It tries it's best to undo changes from a previously sourced setup file before.
# Supported command line options:
# --extend: skips the undoing of changes from a previously sourced setup file

# since this file is sourced either use the provided _CATKIN_SETUP_DIR
# or fall back to the destination set at configure time
: ${_CATKIN_SETUP_DIR:=/opt/ros/hydro}
_SETUP_UTIL="$_CATKIN_SETUP_DIR/_setup_util.py"
unset _CATKIN_SETUP_DIR

if [ ! -f "$_SETUP_UTIL" ]; then
  echo "Missing Python script: $_SETUP_UTIL"
  return 22
fi

# detect if running on Darwin platform
_UNAME=`uname -s`
_IS_DARWIN=0
if [ "$_UNAME" = "Darwin" ]; then
  _IS_DARWIN=1
fi
unset _UNAME

# make sure to export all environment variables
export CMAKE_PREFIX_PATH
export CPATH
if [ $_IS_DARWIN -eq 0 ]; then
  export LD_LIBRARY_PATH
else
  export DYLD_LIBRARY_PATH
fi
unset _IS_DARWIN
export PATH
export PKG_CONFIG_PATH
export PYTHONPATH


# remember type of shell if not already set
if [ -z "$CATKIN_SHELL" ]; then
  CATKIN_SHELL=sh
fi

# invoke Python script to generate necessary exports of environment variables
_SETUP_TMP=`mktemp /tmp/setup.sh.XXXXXXXXXX`
if [ $? -ne 0 -o ! -f "$_SETUP_TMP" ]; then
  echo "Could not create temporary file: $_SETUP_TMP"
  return 1
fi
CATKIN_SHELL=$CATKIN_SHELL "$_SETUP_UTIL" $@ > $_SETUP_TMP
unset _SETUP_UTIL
. $_SETUP_TMP
rm -f $_SETUP_TMP
unset _SETUP_TMP

# source all environment hooks
_i=0
while [ $_i -lt $_CATKIN_ENVIRONMENT_HOOKS_COUNT ]; do
  eval _envfile=\$_CATKIN_ENVIRONMENT_HOOKS_$_i
  unset _CATKIN_ENVIRONMENT_HOOKS_$_i
  eval _envfile_workspace=\$_CATKIN_ENVIRONMENT_HOOKS_${_i}_WORKSPACE
  unset _CATKIN_ENVIRONMENT_HOOKS_${_i}_WORKSPACE
  # set workspace for environment hook
  CATKIN_ENV_HOOK_WORKSPACE=$_envfile_workspace
  . "$_envfile"
  unset CATKIN_ENV_HOOK_WORKSPACE
  _i=$((_i + 1))
done
unset _i

unset _CATKIN_ENVIRONMENT_HOOKS_COUNT

最佳答案

我对setup.sh进行了两项修改,以使其正常运行:

在“调用Python脚本以生成必要的环境变量导出”下进行更改

CATKIN_SHELL=$CATKIN_SHELL "$_SETUP_UTIL" $@ > $_SETUP_TMP




CATKIN_SHELL=$CATKIN_SHELL "$_SETUP_UTIL" $@ >> $_SETUP_TMP


在“ source all environment hooks”下,将while块的终止条件从

while [ $_i -lt $_CATKIN_ENVIRONMENT_HOOKS_COUNT ]; do




while [[ $_i -lt $_CATKIN_ENVIRONMENT_HOOKS_COUNT ]]; do


错误应消失。

参考文献:


cannot overwrite existing file
unary operator expected

关于linux - 来源setup.sh会产生bash错误/tmp/setup.sh.DPE4BtgiZY:无法覆盖现有文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19613046/

10-15 00:08