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

(question) C struct-like template to read positional arguments?



Hi all,

I have question...

In C struct like,
    struct {
	char aa[32], bb[32], skip[128], cc[7], dd[32], ...;
    }
you just access variables, and compiler will do the offsetting.

Can zsh do something similar?

That is, you could probably build the template like
    template=(
	aa 32
	bb 32
	skip 128
	cc 7
	dd 32
	...
    )
and read into them, then just use variables, without worrying about
offsets.  So, ${cc[@]} would be equivalent to ${@:193:7}, and ${cc[1]}
would be same as ${194}.

I know I can do
    aa=( "${@:1:32}" )
    bb=( "${@:33:32}" )
    cc=( "${@:193:7}" )
    ...
But, it's so easy to make mistake and very difficult to catch it.

-- 
William Park <opengeometry@xxxxxxxx>




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