1

I'm collecting -t and -p arguments in arrays, but they turn out empty. The strange thing is, that the same code works as intendet in another function.

declare -a TARGETS
declare -a PACKAGES
while getopts "t:p:" opt ; do
    case $opt in
        t) TARGETS+=("$OPTARG");;
        p) PACKAGES+=("$OPTARG");;
    esac
done
echo ${TARGETS[@]} # empty
echo ${PACKAGES[@]} # empty as well 

The function is called like this:

func -t shared -t INFD_17 -p "barebox.afp=bootloader"  -p "barebox_env.afp=bootloader-env" -p kernel.afp -p rootfs.afp

EDIT: I needed to declare a few variables as local.

local OPTIND t p
declare -a TARGETS
declare -a PACKAGES
while getopts "t:p:" opt ; do
    case $opt in
        t) TARGETS+=("$OPTARG");;
        p) PACKAGES+=("$OPTARG");;
    esac
done
echo ${TARGETS[@]} # empty
echo ${PACKAGES[@]} # empty as well

0 Answers0