Skip to content

evaluate_strictness make the script fail if executed with errexit #163

@nicola-lunghi

Description

@nicola-lunghi

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
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions