Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make variables overwritable by environment #44

Open
CodingMarkus opened this issue Dec 30, 2021 · 0 comments
Open

Make variables overwritable by environment #44

CodingMarkus opened this issue Dec 30, 2021 · 0 comments

Comments

@CodingMarkus
Copy link

CodingMarkus commented Dec 30, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant