mirror of
https://github.com/CHN-beta/nixpkgs.git
synced 2026-01-12 02:40:31 +08:00
patch-shebangs: fix env -S with only one argument
In case `patchShebangs` encounters an `env -S` interpreter with only one
argument following, it would duplicate that argument and most likely invalidate
the resulting interpreter line.
Reproducer:
```nix
(import <nixpkgs> {}).writeTextFile {
name = "patch-shebangs-env-s";
text = ''
#!/bin/env -S bash
'';
executable = true;
checkPhase = ''
patchShebangs $out
'';
}
```
The resulting file would contain
```
#!/nix/store/pw…fk-coreutils-9.5/bin/env -S /nix/store/4f…g60-bash-5.2p37/bin/bash bash
```
instead of the correct
```
#!/nix/store/pw…fk-coreutils-9.5/bin/env -S /nix/store/4f…g60-bash-5.2p37/bin/bash
```
This commit is contained in:
@@ -89,7 +89,7 @@ patchShebangs() {
|
||||
if [[ "$oldPath" == *"/bin/env" ]]; then
|
||||
if [[ $arg0 == "-S" ]]; then
|
||||
arg0=${args%% *}
|
||||
args=${args#* }
|
||||
[[ "$args" == *" "* ]] && args=${args#* } || args=
|
||||
newPath="$(PATH="${!pathName}" type -P "env" || true)"
|
||||
args="-S $(PATH="${!pathName}" type -P "$arg0" || true) $args"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user