From f4f0d2ecb96ee731cd1091c052afa50f0353bb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Fri, 3 Jan 2014 13:55:41 +0100 Subject: [PATCH] stdenv/setup.sh: fix breakage when shebang contains '\' Some programs, e.g. guile-config, has a shebang that ends in '\': #!/usr/bin/guile-1.8 \ -e main -s !# ;;;; guile-config --- utility for linking programs with Guile ;;;; Jim Blandy --- September 1997 This currently breaks patchShebangs: $ read oldPath arg0 args <<< 'shebang \'; echo $? 1 $ echo $oldPath shebang $ echo $arg0 $ echo $args (And setup.sh/patchShebangs is run with 'set -e' so any command that return non-zero aborts the build.) Fix by telling 'read' to not interpret backslashes (with the -r flag): $ read -r oldPath arg0 args <<< 'shebang \'; echo $? 0 $ echo $oldPath shebang $ echo $arg0 \ $ echo $args Also needed: escape the escape characters so that sed doesn't interpret them. --- pkgs/stdenv/generic/setup.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index b7940a069ce7..58647f1508d1 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -677,7 +677,7 @@ patchShebangs() { fi oldInterpreterLine=$(head -1 "$f" | tail -c +3) - read oldPath arg0 args <<< "$oldInterpreterLine" + read -r oldPath arg0 args <<< "$oldInterpreterLine" if $(echo "$oldPath" | grep -q "/bin/env$"); then # Check for unsupported 'env' functionality: @@ -703,7 +703,9 @@ patchShebangs() { if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\"" - sed -i -e "1 s|.*|#\!$newInterpreterLine|" "$f" + # escape the escape chars so that sed doesn't interpret them + escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g') + sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f" fi fi done