[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Read /etc/environment first to allow changing environment fr
From: |
Tobias Geerinckx-Rice |
Subject: |
Re: [PATCH] Read /etc/environment first to allow changing environment from user profile |
Date: |
Wed, 27 Jul 2016 19:18:59 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
Hi Danny,
On 27/07/2016 18:31, Danny Milosavljevic wrote:
>> while read line; do export "$line"; done < /etc/environment
>>
>> I don't know if Guix even cares about non-bash shells, but this
>> should™ work in all POSIX®-compliant ones[4]. It's also more
>> readable.
>>
>> Thoughts? Gotchas?
>
> Spaces in keys and/or values don't work that way.
> The read itself already has problems with them.
No. Perhaps you're confusing it with ‘read < /etc/environment’.
Also, there are no spaces in keys, and technically, spaces in values
work just fine: it's the quotes that don't get dropped. D'oh! :-P
Yeah, trying to emulate unquoting (and all manner of escaping that it
entails) would be utter madness. Uglier option [2] it is then:
. /etc/environment
while read line; export "${line%%=*}"; done < /etc/environment
It's ugly and racy and less straightforward.
But then so was the original, I guess.
> You might try setting IFS="
> " but not sure whether that's standards-compliant.
Setting IFS to a newline doesn't make sense here.
To be honest, I've a personal dislike for IFS, though it is
POSIX-compliant. Saving IFS, setting IFS to ‘=’, running ‘read key
value’, ignoring ‘value’, and restoring IFS would work.
> Also, does csh actually support "export"? The one I have in Solaris
> doesn't. You need to do "setenv" there.
csh isn't a (POSIX) sh.
Thanks for the bug spotting,
T G-R
[1]: It seems to be standard, but I didn't bother testing.
> On 27/07/2016 18:02, Tobias Geerinckx-Rice wrote:
> [2]: even if it didn't, section 2.6.2 of [3] has got you covered
> [3]:
http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html