match and assign variables

Hi guys,

I'm currently writing a script for automating a FreeBSD ZFS setup (ZFSonRooT). I got stuck at one point for raidz(1,2 a.k.a raid5,6) and am in need of assistance.

This is what I need. example:

#!/bin/sh <- must stay sh

echo -n "hdd list: "
read hdd_list
echo -n "hdd label list: "
read hdd_label

[...]
in need of code here
[...]

gpart add -t freebsd-zfs -l <hdd_label> <hdd>

And now for some explaination. The idea is that the user will input a list of hdd's (ex: ad0 ad1 ad2) and then a label for these drives (disk00 disk01 disk02) and in the end I need the last cmd to be executed for each hdd with the coresponding hdd_label, like so:

gpart add -t freebsd-zfs -l disk00 ad0
gpart add -t freebsd-zfs -l disk01 ad1
gpart add -t freebsd-zfs -l disk02 ad2

My problem is that I don't know how to group the first hdd with the first label, second hdd with the second label (and so on) and dinamically create the gpart cmd. Another problem is that the number of hdd's can differ, so it can be (minimum) 3 or 10 (or more), so the script needs to know how many "gpart" cmd it will create and execute, according to the number of hdd's written by the user.

I googled a lot but couldn't find what I'm looking for.

A hint would be most welcomed.

$ a='a b c'
$ b='1 2 3'
$ set -- $a
$ for x in $b; do
>   echo "$1 $x"
>   shift
> done
a 1
b 2
c 3

Wow .... thx, it works. Have to read what each option does. RTFM time.

THX !! :slight_smile: