From 1816ac0db1817642e27ef1544c7d9b904dbb670a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Feb 2015 20:13:53 +0100 Subject: [PATCH] Escape arguments to nix-shell #! scripts --- scripts/nix-build.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/nix-build.in b/scripts/nix-build.in index c7c516212..19de6feb6 100755 --- a/scripts/nix-build.in +++ b/scripts/nix-build.in @@ -195,8 +195,12 @@ for (my $n = 0; $n < scalar @ARGV; $n++) { # or (undocumented) argv[0] does not contain "perl". Exploit # the latter by doing "exec -a". my $execArgs = $interpreter =~ /perl/ ? "-a PERL" : ""; - # FIXME: escape arguments. - $envCommand = "exec $execArgs $interpreter $script @savedArgs"; + sub shellEscape { + my $s = $_; + $s =~ s/'/'\\''/g; + return "'" . $s . "'"; + } + $envCommand = "exec $execArgs $interpreter $script ${\(join ' ', (map shellEscape, @savedArgs))}"; } elsif (substr($arg, 0, 1) eq "-") {