我正在尝试建立一个项目。当我执行bash脚本时,它显示了这个错误:
Harshits-MacBook-Air:build harshitprasad$ . bin/thisroot.sh
sed: -e expression #1, char 47: unterminated `s' command
-bash: sed: No such file or directory
-bash: sed: No such file or directory
-bash: sed: No such file or directory
-bash: sed: No such file or directory
-bash: sed: No such file or directory
-bash: sed: No such file or directory
-bash: sed: No such file or directory
-bash: sed: No such file or directory
-bash: root-config: command not found
-bash: grep: command not found
-bash: grep: command not found
以下是代码:
drop_from_path()
{
# Assert that we got enough arguments
if test $# -ne 2 ; then
echo "drop_from_path: needs 2 arguments"
return 1
fi
local p=$1
local drop=$2
newpath=`echo $p | sed -e "s;:${drop}:;:;g" \
-e "s;:${drop}\$;;g" \
-e "s;^${drop}:;;g" \
-e "s;^${drop}\$;;g"`
}
if [ -n "${ROOTSYS}" ] ; then
old_rootsys=${ROOTSYS}
fi
SOURCE=${BASH_ARGV[0]}
if [ "x$SOURCE" = "x" ]; then
SOURCE=${(%):-%N} # for zsh
fi
if [ "x${SOURCE}" = "x" ]; then
if [ -f bin/thisroot.sh ]; then
ROOTSYS="$PWD"; export ROOTSYS
elif [ -f ./thisroot.sh ]; then
ROOTSYS=$(cd .. > /dev/null; pwd); export ROOTSYS
else
echo ERROR: must "cd where/root/is" before calling ". bin/thisroot.sh" for this version of bash!
ROOTSYS=; export ROOTSYS
return 1
fi
else
# get param to "."
thisroot=$(dirname ${SOURCE})
ROOTSYS=$(cd ${thisroot}/.. > /dev/null;pwd); export ROOTSYS
fi
if [ -n "${old_rootsys}" ] ; then
if [ -n "${PATH}" ]; then
drop_from_path "$PATH" "${old_rootsys}/bin"
PATH=$newpath
fi
if [ -n "${LD_LIBRARY_PATH}" ]; then
drop_from_path "$LD_LIBRARY_PATH" "${old_rootsys}/lib"
LD_LIBRARY_PATH=$newpath
fi
if [ -n "${DYLD_LIBRARY_PATH}" ]; then
drop_from_path "$DYLD_LIBRARY_PATH" "${old_rootsys}/lib"
DYLD_LIBRARY_PATH=$newpath
fi
if [ -n "${SHLIB_PATH}" ]; then
drop_from_path "$SHLIB_PATH" "${old_rootsys}/lib"
SHLIB_PATH=$newpath
fi
if [ -n "${LIBPATH}" ]; then
drop_from_path "$LIBPATH" "${old_rootsys}/lib"
LIBPATH=$newpath
fi
if [ -n "${PYTHONPATH}" ]; then
drop_from_path "$PYTHONPATH" "${old_rootsys}/lib"
PYTHONPATH=$newpath
fi
if [ -n "${MANPATH}" ]; then
drop_from_path "$MANPATH" "${old_rootsys}/man"
MANPATH=$newpath
fi
if [ -n "${CMAKE_PREFIX_PATH}" ]; then
drop_from_path "$CMAKE_PREFIX_PATH" "${old_rootsys}"
CMAKE_PREFIX_PATH=$newpath
fi
if [ -n "${JUPYTER_PATH}" ]; then
drop_from_path "$JUPYTER_PATH" "${old_rootsys}/etc/notebook"
JUPYTER_PATH=$newpath
fi
fi
if [ -z "${MANPATH}" ]; then
# Grab the default man path before setting the path to avoid duplicates
if `which manpath > /dev/null 2>&1` ; then
default_manpath=`manpath`
else
default_manpath=`man -w 2> /dev/null`
fi
fi
if [ -z "${PATH}" ]; then
PATH=$ROOTSYS/bin; export PATH
else
PATH=$ROOTSYS/bin:$PATH; export PATH
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=$ROOTSYS/lib; export LD_LIBRARY_PATH # Linux, ELF HP-UX
else
LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
fi
if [ -z "${DYLD_LIBRARY_PATH}" ]; then
DYLD_LIBRARY_PATH=$ROOTSYS/lib; export DYLD_LIBRARY_PATH # Mac OS X
else
DYLD_LIBRARY_PATH=$ROOTSYS/lib:$DYLD_LIBRARY_PATH; export DYLD_LIBRARY_PATH
fi
if [ -z "${SHLIB_PATH}" ]; then
SHLIB_PATH=$ROOTSYS/lib; export SHLIB_PATH # legacy HP-UX
else
SHLIB_PATH=$ROOTSYS/lib:$SHLIB_PATH; export SHLIB_PATH
fi
if [ -z "${LIBPATH}" ]; then
LIBPATH=$ROOTSYS/lib; export LIBPATH # AIX
else
LIBPATH=$ROOTSYS/lib:$LIBPATH; export LIBPATH
fi
if [ -z "${PYTHONPATH}" ]; then
PYTHONPATH=$ROOTSYS/lib; export PYTHONPATH
else
PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH; export PYTHONPATH
fi
if [ -z "${MANPATH}" ]; then
MANPATH=$ROOTSYS/man:${default_manpath}; export MANPATH
else
MANPATH=$ROOTSYS/man:$MANPATH; export MANPATH
fi
if [ -z "${CMAKE_PREFIX_PATH}" ]; then
CMAKE_PREFIX_PATH=$ROOTSYS; export CMAKE_PREFIX_PATH # Linux, ELF HP-UX
else
CMAKE_PREFIX_PATH=$ROOTSYS:$CMAKE_PREFIX_PATH; export CMAKE_PREFIX_PATH
fi
if [ -z "${JUPYTER_PATH}" ]; then
JUPYTER_PATH=$ROOTSYS/etc/notebook; export JUPYTER_PATH # Linux, ELF HP-UX
else
JUPYTER_PATH=$ROOTSYS/etc/notebook:$JUPYTER_PATH; export JUPYTER_PATH
fi
if [ "x`root-config --arch | grep -v win32gcc | grep -i win32`" != "x" ]; then
ROOTSYS="`cygpath -w $ROOTSYS`"
fi
unset old_rootsys
unset thisroot
unset -f drop_from_path
env
命令的输出:
Harshits-MacBook-Air:build harshitprasad$ env
rvm_bin_path=/Users/harshitprasad/.rvm/bin
TERM_PROGRAM=Apple_Terminal
GEM_HOME=/Users/harshitprasad/.rvm/gems/ruby-2.4.2
SHELL=/bin/bash
TERM=xterm-256color
IRBRC=/Users/harshitprasad/.rvm/rubies/ruby-2.4.2/.irbrc
TMPDIR=/var/folders/c7/b45s17816zn_b1dh3g7yzxrm0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.2va6DsChFN/Render
TERM_PROGRAM_VERSION=400
OLDPWD=/Users/harshitprasad/Desktop/gsoc/root
MY_RUBY_HOME=/Users/harshitprasad/.rvm/rubies/ruby-2.4.2
TERM_SESSION_ID=6A7C8CB1-C291-4A18-BD1F-0090F62984A8
USER=harshitprasad
_system_type=Darwin
rvm_path=/Users/harshitprasad/.rvm
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.fsBTexrYJp/Listeners
rvm_prefix=/Users/harshitprasad
PATH=/anaconda3/bin:/Users/harshitprasad/.rvm/gems/ruby-2.4.2/bin:/Users/harshitprasad/.rvm/gems/ruby-2.4.2@global/bin:/Users/harshitprasad/.rvm/rubies/ruby-2.4.2/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/harshitprasad/.rvm/bin
PWD=/Users/harshitprasad/Desktop/gsoc/root/build
_system_arch=x86_64
XPC_FLAGS=0x0
_system_version=10.13
XPC_SERVICE_NAME=0
rvm_version=1.29.3 (latest)
SHLVL=1
HOME=/Users/harshitprasad
LOGNAME=harshitprasad
GEM_PATH=/Users/harshitprasad/.rvm/gems/ruby-2.4.2:/Users/harshitprasad/.rvm/gems/ruby-2.4.2@global
LC_CTYPE=UTF-8
DISPLAY=/private/tmp/com.apple.launchd.mLrbJ4Ww3r/org.macosforge.xquartz:0
RUBY_VERSION=ruby-2.4.2
_system_name=OSX
_=/usr/bin/env
终端中echo $PATH
的输出:
Harshits-MacBook-Air:~ harshitprasad$ echo $PATH
/anaconda3/bin:/Users/harshitprasad/.rvm/gems/ruby-2.4.2/bin:/Users/harshitprasad/.rvm/gems/ruby-2.4.2@global/bin:/Users/harshitprasad/.rvm/rubies/ruby-2.4.2/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/harshitprasad/.rvm/bin
sed
和grep
安装检查:
Harshits-MacBook-Air:~ harshitprasad$ which sed
/usr/local/bin/sed
Harshits-MacBook-Air:~ harshitprasad$ which -a grep
/usr/bin/grep
我已经检查过,看起来已经安装了sed和grep。我还安装了Xcode v9.2,工作机器是macOS v10.13。我认为这种情况可以通过定义PATH环境变量来解决。
我该如何解决上述问题?我该如何设置环境变量?如果有人能帮帮我的话会很棒!谢谢:))
答案 0 :(得分:2)
从错误消息中,在该脚本的某个位置,您使用第二个参数中包含drop_from_path
的内容调用;
。这会导致sed命令格式错误,给出您看到的第一个错误并将结果newpath
设置为空。由于您在不检查的情况下设置PATH=$newpath
,因此会清除PATH,从而导致所有其他非内置命令失败(您看到的所有其他错误)。