3

I have a Bash script that performs a simple substitution on OS X. Here's the reduced case:

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

When I run it with bash -x it prints eight errors. I can't figure out where the errors are coming from. Searching for the error provides one hit, but I don't quite see the solution.

Where is "gsed: can't read : No such file or directory" coming from?


Below, <full path> is /Users/<username>/<project name>/vs2005-dynamic/. There are no spaces in the pathname.

+ /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
2
  • Does <full path> include spaces? if so, the PROJ_FILES=($(find $PWD -name "*.vcproj")) construction will split them I think: you might want to try something like mapfile -t PROJ_FILES < <(find $PWD -name '*.vcproj') instead Commented May 28, 2016 at 15:26
  • @steeldriver - My bad; no, the path does not include spaces. I shortened it to make it easier to read and avoid horizontal scrolling. I'll update the question. Commented May 28, 2016 at 15:35

1 Answer 1

3

With gsed you don't need the extra '', only with the default OSX sed. Try with either:

SED=/usr/bin/sed

Or:

SEDOPTS=(-i)
2
  • 3
    Worth mentioning the error is caused by the space between -i and "" which instructs gnu sed to edit in-place a file named (nothing) hence the error. Commented May 28, 2016 at 18:39
  • That was it, thanks. You gotta love sed and its nearly useless error messages (and here, ...). Commented May 28, 2016 at 22:04

You must log in to answer this question.