chiark / gitweb /
basic: support default and alternate values for env expansion
authorRay Strode <rstrode@redhat.com>
Tue, 9 Aug 2016 14:20:22 +0000 (10:20 -0400)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:34 +0000 (17:58 +0200)
commit3b148b365934f5baf2c9162e2454ca416b666531
tree4c287c13cfc7abe2a12af943a89e0be6c531ed50
parent70f7776c6e8c549e13adf858c57fe339583c7cec
basic: support default and alternate values for env expansion

Sometimes it's useful to provide a default value during an environment
expansion, if the environment variable isn't already set.

For instance $XDG_DATA_DIRS is suppose to default to:

/usr/local/share/:/usr/share/

if it's not yet set. That means callers wishing to augment
XDG_DATA_DIRS need to manually add those two values.

This commit changes replace_env to support the following shell
compatible default value syntax:

XDG_DATA_DIRS=/foo:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share}

Likewise, it's useful to provide an alternate value during an
environment expansion, if the environment variable isn't already set.

For instance, $LD_LIBRARY_PATH will inadvertently search the current
working directory if it starts or ends with a colon, so the following
is usually wrong:

LD_LIBRARY_PATH=/foo/lib:${LD_LIBRARY_PATH}

To address that, this changes replace_env to support the following
shell compatible alternate value syntax:

LD_LIBRARY_PATH=/foo/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

[zj: gate the new syntax under REPLACE_ENV_ALLOW_EXTENDED switch, so
existing callers are not modified.]
src/basic/fileio.c