I have a problem with using array as parameter in function.
#!/usr/bin/env bash
function array_param
{
local ARRAY_s; local ARRAY_t; local OPTIND
while getopts 's:t:' opt ; do
case "$opt" in
s) ARRAY_s=$OPTARG;;
t) ARRAY_t=$OPTARG;;
esac
done
shift $((OPTIND-1))
echo "ARRAY_s=${ARRAY_s[@]}; ARRAY_t=${ARRAY_t[@]}"
}
array_s=(100 200 300)
array_t=(0 10 3585)
array_param -s ${array_s} -t ${array_t}
Why is only the first element assigned to variables ARRAY_s and ARRAY_t?
Result: ARRAY_s=100; ARRAY_t=0
${array_s}is the first element of the array. Try"${array_s[@]}"ARRAY_s=$OPTARGis also only a string assignment, not an array assignment. What are you trying to do exactly? Copy arrays following the parameters toARRAY_sandARRAY_t?