Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions scripts/upstream/distrobox-enter.upstream
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/sh
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
#
# This file is part of the distrobox project:
Expand Down Expand Up @@ -109,7 +109,7 @@ headless=0
skip_workdir=0
verbose=0
clean_path=0
version="1.8.1.2.1"
version="1.8.2.4"

# Source configuration files, this is done in an hierarchy so local files have
# priority over system defaults
Expand Down Expand Up @@ -422,6 +422,8 @@ generate_enter_command()

result_command="${result_command}
--workdir=${workdir}"
result_command="${result_command}
--env=PWD=${workdir}"
result_command="${result_command}
--env=CONTAINER_ID=${container_name}"
result_command="${result_command}
Expand All @@ -431,15 +433,14 @@ generate_enter_command()
# and export them to the container.
set +o xtrace
# disable logging for this snippet, or it will be too talkative.
for i in $(printenv | grep '=' | grep -Ev ' |"|`|\$' |
grep -Ev '^(CONTAINER_ID|FPATH|HOST|HOSTNAME|HOME|PATH|PROFILEREAD|SHELL|XDG_SEAT|XDG_VTNR|XDG_.*_DIRS|^_)'); do
# We filter the environment so that we do not have strange variables,
# multiline or containing spaces.
# We also NEED to ignore the HOME variable, as this is set at create time
# and needs to stay that way to use custom home dirs.
result_command="${result_command}
--env=${i}"
done
# We filter the environment so that we do not have strange variables or
# multiline.
# We also NEED to ignore the HOME variable, as this is set at create time
# and needs to stay that way to use custom home dirs. or it will be too talkative.
result_command="${result_command}
$(printenv | grep '=' | grep -Ev '"|`|\$' |
grep -Ev '^(CONTAINER_ID|FPATH|HOST|HOSTNAME|HOME|PATH|PROFILEREAD|PWD|SHELL|XDG_SEAT|XDG_VTNR|XDG_.*_DIRS|^_)' |
sed 's/ /\ /g' | sed 's/^\(.*\)$/--env=\1/g')"
Comment on lines +440 to +443

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Env vars with spaces now passed with literal backslashes

The new env-export block escapes spaces with sed 's/ /\\ /g' and then injects the resulting text directly into result_command, but the later assembly loop splits only on newlines, so the backslashes are preserved as part of the argument. If a host variable contains spaces (e.g., MYVAR='foo bar'), the container will now receive MYVAR=foo\ bar instead of MYVAR=foo bar, corrupting the value; previously such vars were simply skipped rather than mis-set.

Useful? React with 👍 / 👎.


# Start with the $PATH set in the container's config
container_paths="${container_path:-""}"
Expand Down Expand Up @@ -704,6 +705,7 @@ if [ "${unshare_groups:-0}" -eq 1 ]; then
if [ "${headless}" -eq 0 ]; then
set -- "--pty" "$@"
fi
set -- "-m" "$@"
set -- "${container_command_user}" "$@"
set -- "su" "$@"
fi
Expand Down