-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Used set to make shell scripts more strict #3278
Conversation
Signed-off-by: Owais Kazi <[email protected]>
✅ Gradle Check success e377fd627404f0913342a70bcc3ffe2960dd5381 |
I agree that |
That's a great question. I'm not sure if there's a way to test these scripts out. I thought gradle check would do the work for us. Any input you have on the same? |
I tried to run these scripts just to see if they will execute and changed |
❌ Gradle Check failure 35839a79ece3130453b2559c8ef8c129d707cfb3 |
start gradle check |
✅ Gradle Check success 35839a79ece3130453b2559c8ef8c129d707cfb3 |
Why did you make this change? Did |
Signed-off-by: Owais Kazi <[email protected]>
Yes, when executed on my local returned
|
what about |
Hey @rursprung! With
|
then i'd suggest to fix them: if you explicitly want to use variable substitution, see e.g. here: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 so instead of writing the specific error you mentioned seems to come from this check for whether the variable is set:
as outlined in this answer the check should probably be written slightly differently: https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash/13864829#13864829 note that ! -z should anyway just be -n .
so i guess something like this should do the trick: if [ -n "${OPENSEARCH_JAVA_HOME:-}" ]; then an experienced shell script developer might have better ideas though :) but i'd strongly suggest to not ignore failures due to unset variables, they can be really tricky to track down if they're not intentional (as with this check which is just a slightly misguided null-check). EDIT: greatly simplified the check suggestion - don't know why i suggested something more complicated before |
Signed-off-by: Owais Kazi <[email protected]>
@rursprung I have added a generalized way for scripts to set using |
good news, thanks! i missed that some still had what about |
If we use
|
@rursprung looking for your A-OK to merge this, thank you for doing a CR |
if possible, i'd like to see if there are corner cases (special scripts) where but if this doesn't work for you / you don't want that i think the PR is already a good step in the right direction! one more thing to consider: maybe it'd make sense to add a small check (GitHub action?) to ensure that the |
@rursprung @dblock created #3343 for the above. We can go ahead and get this merge if everything looks fine. |
* Use set to make shell scripts more strict Signed-off-by: Owais Kazi <[email protected]> * Change -o pipefail to -e Signed-off-by: Owais Kazi <[email protected]> * Set scripts to standard rule Signed-off-by: Owais Kazi <[email protected]> (cherry picked from commit e73a410)
* Use set to make shell scripts more strict Signed-off-by: Owais Kazi <[email protected]> * Change -o pipefail to -e Signed-off-by: Owais Kazi <[email protected]> * Set scripts to standard rule Signed-off-by: Owais Kazi <[email protected]> (cherry picked from commit e73a410) Co-authored-by: Owais Kazi <[email protected]>
Signed-off-by: Owais Kazi [email protected]
Description
Used
set -e -o pipefail
in shell scripts to generalize and ensure that errors are not silently hidden.More on pipefail:
This setting prevents errors in a pipeline from being masked. If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline. By default, the pipeline's return code is that of the last command even if it succeeds.
Issues Resolved
#3106
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.