zsh-users
 help / color / mirror / Atom feed
* zparesopts odd behaviour
@ 2021-09-02 18:26 Roger Mason
  0 siblings, 0 replies; only message in thread
From: Roger Mason @ 2021-09-02 18:26 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-02 20:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02 18:26 zparesopts odd behaviour Roger Mason

zsh-users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ https://inbox.vuxu.org/zsh-users \
		zsh-users@zsh.org
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git