« first day (1285 days earlier)      last day (3652 days later) » 
00:00 - 23:0023:00 - 00:00

11:00 PM
1
A: How do I source another process's environment variables?

Mark PlotnickThe following will convert each environment variable into an export statement, properly quoted for reading into a shell (because LS_COLORS, for example, is likely to have semicolons in it), then sources it. [The printf in /usr/bin, unfortunately, generally doesn't support %q, so we need to call ...

^^^^ please upvote this answer and downvote the three with horrible lack of escaping
All the others utterly fail if the value of any environment variable contains characters that the shell expands
 
@Gilles Done. That's a very nice answer. But can environmental variables contain newlines?
Ah, yes, obviously of course they can. PS1 comes to mind. Never mind.
 
11:42 PM
^^^For all yee reading the above, please don't DV me. I added an answer with other ways to address this issue.
 
@Graeme amended
 
Apart from the fact that the last one was vulnerable to variable expansion, fixed now though.
 
@fr00tyl00p export EXAMPLE="No, you aren't quite there yet"Gilles 5 mins ago
You have a sarcastic streak in you Gilles.
 
@Graeme not quite (but best in show so far). One problem is easily fixed: sed "s/'/'\''/g; s/=/='/; s/$/'/" (otherwise you end up with some spurious quotes)
but then there's the problem of multi-line values, harder to fix
 
@Gilles Oops, yes, just use printf %s
 
11:53 PM
@Graeme no, won't help
echo is actually fine here, because VAR=VALUE never looks like an option
but think of VAR="" vs VAR=$'\n'
 
@Gilles ah
 
oh, and read -d "" to read null-separated fields isn't POSIX
even though dash supports it
also you need read -r
 
@Gilles What makes a shell POSIX? Does it simply need to conform to the specs or does it have to provide only what's described by them?
 
@terdon needs to conform to the specs
 
So extra functionality is fine?
 
11:58 PM
sure
 
So bash and zsh lack POSIX features?
I had always thought of POSIX shells as being much more limited.
 
no, bash and zsh do more than POSIX
(they actually do lack some very minor features, they aren't 100% compliant, but close)
 
00:00 - 23:0023:00 - 00:00

« first day (1285 days earlier)      last day (3652 days later) »