Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zparesopts odd behaviour
- X-seq: zsh-users 27071
- From: Roger Mason <rmason@xxxxxx>
- To: zsh-users@xxxxxxx
- Subject: zparesopts odd behaviour
- Date: Thu, 02 Sep 2021 15:56:07 -0230
- Archived-at: <https://zsh.org/users/27071>
- Ironport-hdrordr: A9a23:jTc3pqs08euomEStr5rxuN/g7skCxIMji2hC6mlwRA09TyXGra2TdaUgvyMc1gx7ZJh5o6H6BEGBKUmslqKdkrNhR4tKPTOW9FdASbsP0WKM+UyGJ8STzI9gPOJbAtBD4b7LfBdHZKTBkW+F+r8bqbHpnpxAx92utkuFJjsaCZ2Imj0JbjpzZXcGITWua6BYKLOsou584xawc3Ueacq2QlMfWfLYmtHNnJX6JTYbGh8O8mC1/HKVwY+/NyLd8gYVUjtJz7tn23PCiRbF6qKqtOz+4gPA1lXU849dlLLau5t+7Y23+4sowwfX+0OVjbdaKvm/VfcO0aaSAWMR4ZvxStEbToJOAj3qDziISFDWqnTdOX4VmgPfIBmj8DXeSIXCNU0HItsEioRDfhTD7U08+Nl6zaJQxmqc84FaFBXagU3GlpD1vr5R5zmJSFcZ4JguZkZkIMIjgX5q3P4i1VIQFI1FEDPx6YghHuUrBMbA5OxOeVffa3zCpGFgzNGlQ3x2R369MwI/k93Q1yITkGFyzkMeysBalnAc9IglQ50B4+jfKKxnmLxHU8dTZ6NgA+UKR9exFwX2MFnxGXPXJU6iGLAMOnrLpZKy6LIp5PuycJhN15c2kISpaiIuiYfzQTObNSSq5uwHzvngehTNYd3d8LAq23EigMyDeFPCC1zydGwT
- Ironport-sdr: aT6X9EiQPYry1Po5EJ1uMIsXJHLeblM9pZVtNlm5aQBxqzeCLUZNhIYpaWczeggcxQSFkLn42H 06Gj+qeyPY7NkLhS29YEnHPKrkQDrMi9vVQDt5gMixFguMnledsjQvW4CIxnZ4sVsFjYzDcbtm AAZI7S8Nm20tmwdb5SfQOq8CdgVQYTCdEemfhD/OSBTrskAmh+GR4lO6FHlMKfZHZ765pY8Xrh EjjLUiqDTSHG6SOdlnM1QeN279EUXqb/8LoC89Hi+2RgTFlfPzBmPGkJSXCClw8OH7GHwxnbA/ XWw=
- List-id: <zsh-users.zsh.org>
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