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

evaluate_strictness make the script fail if executed with errexit #163

Open
nicola-lunghi opened this issue Sep 30, 2022 · 1 comment
Open

Comments

@nicola-lunghi
Copy link

The following statement

evaluate_strictness()
{
    [["$2" =~ ^-(-(config|command|help|version)$|[chv]) ]] && die "You have passed '$2' as a value of argument '$1', which makes it look like that you have omitted the actual value, since '$2' is an option accepted by this script. This is considered a fatal error."
}

Make the script fail if setopt -o errexit is set, as if the comparison is "false" the return value is also false -> and bash kill the process.
One solution could be to negate the comparison:

evaluate_strictness()
{
    [[ ! "$2" =~ ^-(-(config|command|help|version)$|[chv]) ]] || die "You have passed '$2' as a value of argument '$1', which makes it look like that you have omitted the actual value, since '$2' is an option accepted by this script. This is considered a fatal error."
}

Or add a return 0 after the [[]], like

evaluate_strictness()
{
[["$2" =~ ^-(-(config|command|help|version)$|[chv]) ]] && die "You have passed '$2' as a value of argument '$1', which makes it look like that you have omitted the actual value, since '$2' is an option accepted by this script. This is considered a fatal error."
return 0
}

@nicola-lunghi
Copy link
Author

see my proposed fix #167

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

1 participant