Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zparesopts odd behaviour



Hello,

Given this script:

#!/usr/local/bin/zsh -f
ELKVER=elk-7.1.14

floats=($(awk '/!     default values     !/{flag=1;next}/!     read from elk.in     !/{flag=0}flag' \
~/Software/Elk/$ELKVER/src/readinput.f90 \
| awk '!/!/' | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' \
| awk '{gsub(/ /,""); print}' | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \
| awk '{gsub(/=/," "); print}' | awk '$2 ~ /[0-9]+(\.)[0-9]*/ {print "-"$1":"}'))

echo "$floats"

#zparseopts -D -E -A elkfloats - -sc: -sc1: -sc2: -sc3:
zparseopts -D -E -A elkfloats - ${floats}
OPTSELK=""

for key value in "${(@kv)elkfloats}"; do
    k=$(echo $key | tr -d '-')
    ${k}=${elkfloats[$key]} 2>/dev/null # Discard error message: command not found:
    if [[ $k == sc* ]];then		# sc is used internally in the elk code vs elk.in.
	k=$(echo $k | sed 's/sc/scale/g') # Should work on sc1, sc2 & sc3.
#	echo "$k = $value"
    fi
      OPTSELK+="$k\n $value\n\n"
done
echo "$OPTSELK"
exit 10

Called like this:

./testopts.sh  --sc1 5.5 --sc2 5.5 --sc3 8.0 --sc 1.5

I get this output:

-afindscf: -amixpm_1: -amixpm_2: -avec_1_1: -avec_2_2: -avec_3_3: -avecu_1_1: -avecu_2_2: -avecu_3_3: -befvit: -broydpm_1: -broydpm_2: -c_tb09: -chgexs: -deapwlo: -deltaem: -deltaph: -deltast: -demaxbnd: -dengy0: -dlefe: -dncgga: -dtimes: -ecvcut: -ehfb: -emaxelnes: -emaxrf: -ephscf_1: -ephscf_2: -epsband: -epschg: -epsdev: -epsefm: -epsefvit: -epsengy: -epsforce: -epslat: -epsocc: -epspot: -epsstress: -esccut: -evaltol: -fracinr: -fxclrc_1: -fxclrc_2: -gmaxrf: -gmaxvr: -hkmax: -hmaxvr: -hybridc: -mstar: -mustar: -nempty0: -nrmtscf: -q0cut: -radkpt: -rdmalpha: -rdmtemp: -reducebf: -rgkmax: -rmtall: -rmtdelta: -rndatposc: -rndavec: -rndbfcmt: -rndbfcu: -rndevt0: -sc1: -sc2: -sc3: -sc: -scissor: -scu1: -scu2: -scu3: -scu: -socscf: -solscf: -sqados_3: -swidth: -sxcscf: -t0tdlr: -tau0atp: -tau0latv: -tauefm: -taufsm: -tauftm: -tauoep_1: -tauoep_2: -taurdmc: -taurdmn: -tdphi: -thetamld: -trial_step: -tstime: -vclp2d_1_1: -vclp2d_2_2: -vclp3d_1_1: -vclp3d_2_2: -vclp3d_3_3: -vhmat_1_1: -vhmat_2_2: -vhmat_3_3: -wmaxgw: -wphcut: -wplot_1: -wplot_2: -wsfac_1: -wsfac_2:
scale
 1.5

The output I expect is:

scale
 1.5

scale1
 5.5

scale2
 5.5

scale3
 8.0

The option names are extracted from variable names in a piece of fortran
code.  The line 'echo floats' in the script is just for debugging, it
verifies that the options are being parsed correctly from that code.

If I call the script thus:

./testopts.sh  --sc1 5.5 --sc2 5.5 --sc3 8.0

the output (without the debugging line) is:

scale
 3

When called thus:

./testopts.sh  --sc1 5.5 --sc2 5.5

I get

scale
 2

It looks like zparseopts is confusing the option and the option
argument, but perhaps something else is going on.

I'm running zsh-5.8 on FreeBSD 11.4.

I appreciate any help in getting this to work correctly.

Thanks,
Roger




Messages sorted by: Reverse Date, Date, Thread, Author