Bug 1525593

Summary: show variables containing spaces in 'systemctl show -p Environment'
Product: [Fedora] Fedora Reporter: Pavel Raiskup <praiskup>
Component: systemdAssignee: systemd-maint
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: lnykryn, msekleta, s, systemd-maint, zbyszek
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: systemd-246~rc1-1.fc33 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-07-09 08:50:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Pavel Raiskup 2017-12-13 16:05:52 UTC
$ systemctl show -p Environment postgresql.service
..  PG_OOM_ADJUST_VALUE=0 [unprintable] ...

The "unprintable" variable is set by:

   Environment=PGDATA=/var/lib/pgsql/'da ta'

Or by:

   Environment='PGDATA=/var/lib/pgsql/da ta'

and there's actually nothing "unprintable" on that. It would be nice
if systemctl could quote && print that variable, too.

Comment 1 Lukáš Nykrýn 2017-12-14 11:43:42 UTC
Looks like upstream systemd uses escaping in this case.
[root@notas ~]#  systemctl show -p Environment cups.service
Environment=PGDATA=/var/lib/pgsql/da\x20ta

Comment 2 Pavel Raiskup 2017-12-14 13:10:04 UTC
Good, thanks - just for reference - could we link the upstream implementation
(the escaping) from here?  I'd like to ensure that something like this works:

#! /bin/bash
systemd_output=$(systemctl show -p Environment "$1")
set -- ${systemd_output##Environment=}
for item; do
    name=${item%%=*}
    value=$(echo -e "${item##*=}")
    eval "$name=\$value"
done

Comment 3 Lukáš Nykrýn 2017-12-14 13:13:39 UTC
I guess you want to call systemd-escape --unescape on the string.

Comment 4 Pavel Raiskup 2017-12-14 13:22:53 UTC
Thanks, nice to know :-) but I guess I still need to split the environment
variables, somehow.

Comment 5 Zbigniew Jędrzejewski-Szmek 2017-12-16 14:49:55 UTC
Upstream used to do that, but it doesn't anymore :(
https://github.com/systemd/systemd/commit/5993d46a1a

Comment 6 Zbigniew Jędrzejewski-Szmek 2020-04-06 08:59:40 UTC
https://github.com/systemd/systemd/pull/15345

Comment 7 Zbigniew Jędrzejewski-Szmek 2020-07-09 08:50:08 UTC
Built in rawhide.