ttfautohint-build icon indicating copy to clipboard operation
ttfautohint-build copied to clipboard

Make variables overwritable by environment

Open CodingMarkus opened this issue 3 years ago • 0 comments

Variables like

BUILD="$HOME/ttfautohint-build"
INST="$BUILD/local"

should be customizable without having to alter your build script. An easy way to do that is by allowing them to be overwritten through environment variables. So if I want a custom build dir, I would just run

BUILD="/tmp/build" ./ttautohint-build.sh

To make that possible, you want to have your code work like this

if [ -z "$BUILD" ]
then
    BUILD="$HOME/ttfautohint-build"
fi

so if $BUILD is already set, just take the value and don't set your own one. Only set a value if no value is set in environment.

And there exists a much easier way to write the code above, which is even POSIX shell conform and thus supported by all shells:

: "${BUILD:="$HOME/ttfautohint-build"}"

That's it. It will set $BUILD only if not already set.

CodingMarkus avatar Dec 30 '21 23:12 CodingMarkus