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

use POSIX parameter expansion for assigning default values #202

Open
umlaeute opened this issue Aug 31, 2023 · 2 comments
Open

use POSIX parameter expansion for assigning default values #202

umlaeute opened this issue Aug 31, 2023 · 2 comments

Comments

@umlaeute
Copy link
Contributor

the modules are full of default-assignments like so:

[ -n "$BASE_IMAGE_RASPBIAN" ] || BASE_IMAGE_RASPBIAN=yes

this is obviously not a bug, but i think the readability could be improved by using POSIX parameter expansion.

the following is equivalent to the test-clause above:

: ${BASE_RELEASE_COMPRESS:=yes}

from the bash manpage:

${parameter:=word} Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.

@guysoft
Copy link
Owner

guysoft commented Aug 31, 2023

So it would be in the config file:

BASE_IMAGE_RASPBIAN=${BASE_RELEASE_COMPRESS:=yes}

?

I want to assign default values there because its also where people go to look what they can set.

@umlaeute
Copy link
Contributor Author

i'm not sure what you mean.
your example would

  1. set BASE_RELEASE_COMPRESS to yes unless it is already set to a non-empty value
  2. set BASE_IMAGE_RASPBIAN to the value of BASE_RELEASE_COMPRESS (from item1)

i guess that mixing of BASE_IMAGE_RASPBIAN and BASE_RELEASE_COMPRESS was just a typo.

my line:

: ${BASE_RELEASE_COMPRESS:=yes}

does:

  1. set BASE_RELEASE_COMPRESS to yes unless it is already set to a non-empty value
  2. nothing else (as : is a nop-command)

you can of course use variables on the right-hand term as well:

: ${BASE_IMAGE_PATH:=${DIST_PATH}/image}

but if you feel that this is just busy-work, feel free to ignore (and possibly close) this ticket

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

No branches or pull requests

2 participants