“gsed:无法读取:没有这样的文件或目录”的来源?

“gsed:无法读取:没有这样的文件或目录”的来源?

我有一个 Bash 脚本,可以在 OS X 上执行简单的替换。这是简化的情况:

mkdir vs2005-dynamic
cp cryptdll.vcproj cryptest.sln cryptest.vcproj cryptlib.vcproj dlltest.vcproj vs2005-dynamic/
cd vs2005-dynamic
...

SED=/opt/local/bin/gsed
SEDOPTS=(-i "")
...

PROJ_FILES=($(find $PWD -name "*.vcproj"))
for pf in "${PROJ_FILES[@]}"; do
  "$SED" "${SEDOPTS[@]}" -e 's|RuntimeLibrary="0"|RuntimeLibrary="2"|g' "$pf"
  "$SED" "${SEDOPTS[@]}" -e 's|RuntimeLibrary="1"|RuntimeLibrary="3"|g' "$pf"
done

当我运行它时,bash -x它会打印八个错误。我无法弄清楚错误来自哪里。正在寻找错误提供一击,但我不太明白解决方案。

哪里“gsed:无法读取:没有这样的文件或目录”来自(哪里?


下边<full path>/Users/<username>/<project name>/vs2005-dynamic/。路径名中没有空格。

+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="0"|RuntimeLibrary="2"|g' <full path>/cryptdll.vcproj
/opt/local/bin/gsed: can't read : No such file or directory
+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="1"|RuntimeLibrary="3"|g' <full path>/cryptdll.vcproj
/opt/local/bin/gsed: can't read : No such file or directory
+ for pf in '"${PROJ_FILES[@]}"'
+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="0"|RuntimeLibrary="2"|g' <full path>/cryptest.vcproj
/opt/local/bin/gsed: can't read : No such file or directory
+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="1"|RuntimeLibrary="3"|g' <full path>/cryptest.vcproj
/opt/local/bin/gsed: can't read : No such file or directory
+ for pf in '"${PROJ_FILES[@]}"'
+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="0"|RuntimeLibrary="2"|g' <full path>/cryptlib.vcproj
/opt/local/bin/gsed: can't read : No such file or directory
+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="1"|RuntimeLibrary="3"|g' <full path>/cryptlib.vcproj
/opt/local/bin/gsed: can't read : No such file or directory
+ for pf in '"${PROJ_FILES[@]}"'
+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="0"|RuntimeLibrary="2"|g' <full path>/dlltest.vcproj
/opt/local/bin/gsed: can't read : No such file or directory
+ /opt/local/bin/gsed -i '' -e 's|RuntimeLibrary="1"|RuntimeLibrary="3"|g' <full path>/dlltest.vcproj
/opt/local/bin/gsed: can't read : No such file or directory

答案1

使用 gsed,您不需要额外的 '',只需使用默认的 OSX sed。尝试使用以下任一方法:

SED=/usr/bin/sed

或者:

SEDOPTS=(-i)

相关内容