Skip to content

-? in arg parsing can cause frustrating problems sourcing zopen-config #1166

@covener

Description

@covener

Description

When sourcing zopen-config, the -? in the options parsing matches any short option because ? is a single-character glob not a literal.

On its own this is fine, but when you source a file in bash, args from the current process are available in the sourced script, so sourcing zopen-config from any shell process that has a short option causes the usage()output to be issued and no ZOT env changes.

[...] If any arguments are supplied, they become the positional parameters when filename is executed. Otherwise the positional parameters are unchanged.

while [ $# -gt 0 ]; do
  case "$1" in
    --eknv) exportknv="export "; knv=true;;
    --knv) knv=true;;
    --override-zos-tools)  export ZOPEN_TOOLSET_OVERRIDE=1;;
    --nooverride-zos-tools)  unset ZOPEN_TOOLSET_OVERRIDE;;
    --override-zos-tools-subset) shift;  export ZOPEN_TOOLSET_OVERRIDE=1; overrideFile="$1";;
    --quiet) displayText=false;;
    -?|--help) displayHelp; return 0;;
  esac
  shift
done

Since there is no *) case I don't think it's intentionally trying to capture all unknown arguments and is just a globbing mistake.

Severity

Sev 4 - Low

Expected Behavior

I am not sure about this, but it is a confusing thing to debug.

options:

  1. ignore unknown short options just like very other unknown argument, by escaping the ? (backslash or put it in a [] character class)
  2. If we continue to fail, complain about the arg value or entire argv so it is more clear to someone debugging that they have passed args to their script/login shell inadvertently so they can learn about this source behavior too
  3. Maybe change examples to avoid the inadvertent passing of args, unfortunately just "--" doesn't work, but --noargs does

Actual Behavior

callers args are passed by bash itself where they might trigger displayHelp()

z/OS Version

3.2

zopen package manager version

0.8.4

Additional Information (Optional)

for the below test.sh, try ./test.sh -b and you can see the help get triggered on the first call.

#!/usr/bin/env bash

ZOPEN_HOME=/usr/local/zopen

echo "first source"
source $ZOPEN_HOME/etc/zopen-config 2>&1 | tail -1

echo "second source"
source $ZOPEN_HOME/etc/zopen-config --noargs

Network or Security Configuration (Optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Sev 4 - LowMinor issuebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions