#!/bin/bash set -- -h -c foo x y z global FLAG_h := '0' global FLAG_c := '''' while getopts "hc:" opt { echo "status $Status" echo "OPT $opt" matchstr $opt { h { global FLAG_h := '1' } c { global FLAG_c := $OPTARG } ? { echo ERROR; break } } } shift $( OPTIND - 1 ) echo h=$FLAG_h c=$FLAG_c optind=$OPTIND argv=$ifsjoin(Argv) (CommandList children: [ (C {(set)} {(--)} {(-h)} {(-c)} {(foo)} {(x)} {(y)} {(z)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:FLAG_h) op:Equal rhs:{(0)} spids:[20])] spids: [20] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:FLAG_c) op:Equal rhs:{(SQ )} spids:[23])] spids: [23] ) (While cond: [(C {(getopts)} {(DQ ("hc:"))} {(opt)})] body: (DoGroup children: [ (C {(echo)} {(DQ ("status ") ($ VSub_QMark "$?"))}) (C {(echo)} {(DQ ("OPT ") ($ VSub_Name "$opt"))}) (Case to_match: {($ VSub_Name "$opt")} arms: [ (case_arm pat_list: [{(h)}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:FLAG_h) op:Equal rhs:{(1)} spids:[66])] spids: [66] ) ] spids: [63 64 69 -1] ) (case_arm pat_list: [{(c)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:FLAG_c) op: Equal rhs: {(DQ ($ VSub_Name "$OPTARG"))} spids: [75] ) ] spids: [75] ) ] spids: [72 73 80 -1] ) (case_arm pat_list: [{(Lit_Other "?")}] action: [ (Sentence child: (C {(echo)} {(ERROR)}) terminator: ) (ControlFlow token:) ] spids: [83 84 93 -1] ) ] spids: [56 60 96] ) ] spids: [37 98] ) ) (C {(shift)} { (ArithSubPart anode: (ArithBinary op_id: Arith_Minus left: (ArithVarRef name:OPTIND) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [102 111] ) } ) (C {(echo)} {(Lit_VarLike "h=") ($ VSub_Name "$FLAG_h")} {(Lit_VarLike "c=") ($ VSub_Name "$FLAG_c")} {(Lit_VarLike "optind=") ($ VSub_Name "$OPTIND")} {(Lit_VarLike "argv=") ($ VSub_At "$@")} ) ] )