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.
usually, to avoid empty string, we can do x"$describe" == x"$latest_tag"
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.
The convention you describe doesn't fix this issue. Prepending an "x" to the string only will prevent a bash error if either of the strings are empty (and unquoted). For example:
if [ x$VAR1 == x$VAR2 ]
. In this case, if VAR1 is empty and VAR2 contains "somestring", the statement would expand toif [ x == somestring ]
, whereas without the x's, it would expand toif [ == somestring ]
, which is invalid syntax and cause the script to crash. With quotes (if [ x"$VAR1" == x"$VAR2" ]
, this would evaluate toif [ x == xsomestring ]
, thus making a valid statement which would correctly return false. There is no need to prepend characters if the variables in the conditional are quoted.In the case presented here, however, the strings are already quoted, so we don't have to worry about a crash. In fact, the issue here stems from both strings being empty. However, adding x's here doesn't solve the issue, because both
latest_tag
anddescribe
are empty strings, so this comparison returns true, and will continue to return true if we prepend x's, so the result will be the same: sincelatest_tag
is empty, sonic_get_version() would still return an empty string.