Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I'm working on this file and don't know what "+x" in
${DISABLE_XIP+x}
does. (AFAICS, it is also not mentioned in the Bash manual.) Could you please explain?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's parameter expansion:
So if
DISABLE_XIP
is null or unset then the check will fail otherwise it will pass.x
is used here just as a placeholder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out I've missed the part where it explains that the colon can be omitted:
Thanks!
I think I will change this to
[[ $DISABLE_XIP != true ]]
like I did with all the other boolean-y variables.To be honest,
${DISABLE_XIP+x}
looks ugly. I have completely rewritten this script and this is the last part of the whole thing that I could not understand. I don't like saying "If that was hard for me, then it will be for other people." but I guess this one deserves an exception.Also, correct me if I'm wrong, but if a variable is set and I want to run a single command with that variable being unset, I have to use
unset DISABLE_XIP; command
which unsets the variable for the whole env and not just the command. A subshell can be used to avoid that but it just gets uglier. With a!= true
check, you can just doDISABLE_XIP= command;
to turn it off andDISABLE_XIP=true command;
to turn it on. This doesn't really matter in this use case, but I guess I will adopt this as one of my "Bash Best Practices".What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that sounds completely reasonable and a nicer solution all round. Thanks!