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