coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

env: can it be used to let only certain variables through (if they're se


From: Christoph Anton Mitterer
Subject: env: can it be used to let only certain variables through (if they're set)?
Date: Fri, 21 Jan 2022 01:28:51 +0100
User-agent: Evolution 3.42.2-1

Hey.

What I'd like to do, is set up a shebang line e.g. for shell scripts,
so that the environment (in terms of variables) it gets is kinda
predictable.

For certain tasks this is very easy, e.g. I can set some
PATH=/usr/bin:/bin or so.

It's also easy to filter out anything I don't set in specific, by using
-i ... so I can get rid of things like POSIXLY_CORRECT which would
alter behaviour of tools like GNU's sed & friends... and also
everything in terms of such variable which I don't even think about.



Now what I cannot get fully working, is to let certain variables
through, only if they are set.
E.g. it could make sense to block LC_CTYPE, but let LC_MESSAGES
through.

/usr/bin/env -iS 'LC_MESSAGES=${LC_MESSAGES} command args'

get's close to it, but has the problem that LC_MESSAGES is set (though
empty) if it wasn't set outside.

And there are env vars, which have altering behaviour to certain
programs, purely when they're set (regardless of whether empty or so).



On the command line (i.e. without shebang) I can do:

/usr/bin/env -i ${LC_MESSAGES+"LC_MESSAGES=${LC_MESSAGES}"} command args

can this be done for -S, too? Or added as a feature?


Thanks,
Chris.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]