Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

bash - What is ${DEBUG- } means in yaml config?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure about YAML, but in bash, the expression ${VARNAME-DEFAULT} means: Replace by the contents of the variable VARNAME if it exists, otherwise use DEFAULT

Here's an example:

$ echo "Hello ${PL-Earth}"
Hello Earth
$ PL=Neptune
$ echo "Hello ${PL-Earth}"
Hello Neptune
$ unset PL
$ echo "Hello ${PL-Earth}"
Hello Earth

When I look at your yaml file, it looks very similar: If DEBUG is set, use whatever is set, otherwise use a single space, etc. This is actually a common usage, adding the line

DEBUG=${DEBUG- }

ensures that a variable with the name DEBUG exists, even if it contains only a space.

Well, as for how to use it, set the corresponding environment variables before you execute whichever program uses this yaml file.

$ export DEBUG='-g -O0 -fbacktrace -Wall'
$ <Call to program>

I don't know much about docker, but there is almost certainly a way to set environment variables in a docker configuration.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...