linux exec文件中忽略空格字符

时间:2015-02-03 21:26:45

标签: linux shell exec

我试图运行以下脚本

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo ${DIR}
source ${DIR}/envcov.sh

在回声上,输出是

/Users/John/Desktop/Test/Test Banking/XcodeCoverage

执行到达时

   source ${DIR}/envcov.sh

我收到以下错误

 ./getcov: line 7: /Users/John/Desktop/Test/Test: No such file or directory

未处理空格字符。知道如何克服这个问题吗?

修改

source "${DIR}/envconv.sh" 

添加双引号会引发错误:

/Users/John/Desktop/Test/Test Banking/XcodeCoverage/envconv.sh: No such file or directory.

我需要通过查找变量$ {DIR}中空格字符的索引来添加退格键,如下所示:

/Users/John/Desktop/Test/Test\ Banking/XcodeCoverage/envconv.sh

1 个答案:

答案 0 :(得分:1)

是的,您需要对参数进行双重引用:

source "${DIR}/envconv.sh"