Compare commits

..

3 commits

Author SHA1 Message Date
383b243ebd Improve quine printf 2026-10-23 17:39:46 +02:00
f1573d922d Exec bash and reset IFS to default 2026-10-23 17:39:36 +02:00
d64c54f994 Fix comment 2026-10-21 18:19:04 +02:00

View file

@ -62,9 +62,11 @@ bashrc_forward () {
printf %s '
#-# If bashrc was forwarded using environment variable, unset it, since we do not need it anymore and to keep the env clean. Relaying will set it anyways to something fresh.
unset FORWARDED_BASHRC
#-# Set default IFS, since our staging command line may not contain double quotes since they behave weirdly in powershell.
IFS=$(printf '\'' \t\n.'\''); IFS=${IFS%.}
_argv_wrap () {
if >/dev/null 2>&1 command -v bash; then
bash -c '\''
exec bash -c '\''
#-# Newest Bash feature used here is parameter transformation (`${_s@A}`), introduced in Bash 4.4
if ! ((BASH_VERSINFO[0]>4||(BASH_VERSINFO[0]==4&&BASH_VERSINFO[1]>=4))) 2>/dev/null; then
>&2 echo "Failed to SSH with .bashrc-forwarding, the Bash version is too old."
@ -92,18 +94,14 @@ bashrc_forward () {
[[ "${ENV##*/}" =~ ^[0-9]+$ ]] && builtin eval "builtin exec ${ENV##*/}<&-"
#-# Constructs new ENV after every command, thanks to the quine
builtin exec {ENV}< <(
printf %s "${_s@A}
$_s"
)
builtin exec {ENV}< <(printf "%s\\n%s" "${_s@A}" "$_s")
export ENV="/dev/fd/$ENV"
'\''\'\'''\''\'\''\'\'''\'''\''\'\'''\''
'\''\'\'''\''
printf %s "${_s@A}
$_s"
printf "%s\\n%s" "${_s@A}" "$_s"
#-# Suppress the warning `bash: POSIXLY_CORRECT: readonly variable` using a one-shot DEBUG trap
#-# `PS0` and `PROMPT_COMMAND` will not suffice, `PROMPT_COMMAND` runs AFTER the command, therefore
@ -145,7 +143,7 @@ bashrc_forward () {
if [ "$#" -gt 0 ]; then
exec "${SHELL:-${0#-}}" "$@"
else
>&2 echo "Failed to SSH with .bashrc-forwarding, could not find Bash binary."
>&2 echo "Failed to forward .bashrc, could not find Bash binary."
>&2 echo "Please install Bash 4.4 or newer on the target system and make it available in the PATH."
>&2 echo "Falling back to default shell (warning, possibly not a login shell anymore!): '\''${SHELL:-${0#-}}'\''."
#-# Using generic `exec` call instead of fancy `exec -l --` because we cannot assume that we are inside Bash.