diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index b57698cb90b3..83464a759a58 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -913,9 +913,9 @@ substitute ./foo.in ./foo.out \ --subst-var someVar ``` -### `substituteInPlace` \ \ {#fun-substituteInPlace} +### `substituteInPlace` \ \ {#fun-substituteInPlace} -Like `substitute`, but performs the substitutions in place on the file \. +Like `substitute`, but performs the substitutions in place on the files passed. ### `substituteAll` \ \ {#fun-substituteAll} diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index de8d13160f93..0ba8d1018233 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -771,9 +771,18 @@ substitute() { } substituteInPlace() { - local fileName="$1" - shift - substitute "$fileName" "$fileName" "$@" + local -a fileNames=() + for arg in "$@"; do + if [[ "$arg" = "--"* ]]; then + break + fi + fileNames+=("$arg") + shift + done + + for file in "${fileNames[@]}"; do + substitute "$file" "$file" "$@" + done } _allFlags() {