Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
(question) C struct-like template to read positional arguments?
- X-seq: zsh-users 26389
- From: William Park <opengeometry@xxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: (question) C struct-like template to read positional arguments?
- Date: Sun, 17 Jan 2021 20:52:52 -0500
- Archived-at: <https://zsh.org/users/26389>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-01/20210118015252.GA3550%40node1.localdomain>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxx>
- References: <20210118015252.GA3550.ref@node1.localdomain>
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