patch-shebangs: handle env -S shebangs

`env -S` allows one to set more than one argument in a shebang. This
small patch allows the patch-shebangs hook to handle this case
appropriately.
This commit is contained in:
Timothy DeHerrera 2022-09-17 18:35:07 -06:00 committed by Artturin
parent ee54eb7d21
commit 792907e3bf

View file

@ -62,15 +62,21 @@ patchShebangs() {
fi
if [[ "$oldPath" == *"/bin/env" ]]; then
if [[ $arg0 == "-S" ]]; then
arg0=${args%% *}
args=${args#* }
newPath="$(PATH="${!pathName}" command -v "env" || true)"
args="-S $(PATH="${!pathName}" command -v "$arg0" || true) $args"
# Check for unsupported 'env' functionality:
# - options: something starting with a '-'
# - options: something starting with a '-' besides '-S'
# - environment variables: foo=bar
if [[ $arg0 == "-"* || $arg0 == *"="* ]]; then
elif [[ $arg0 == "-"* || $arg0 == *"="* ]]; then
echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" >&2
exit 1
else
newPath="$(PATH="${!pathName}" command -v "$arg0" || true)"
fi
newPath="$(PATH="${!pathName}" command -v "$arg0" || true)"
else
if [[ -z $oldPath ]]; then
# If no interpreter is specified linux will use /bin/sh. Set