For some reason in the code below for loop treats args as array and wc -l can count the lines correctly but I can't get the $(#args[@]) to produce the correct count
function doSomthing() {
local i args a
args=$1;
a=("1" "2" "3" "4");
i=0
echo wc =`wc -l <<< "$args"`;
for arg in $args; do
((i++))
echo "$i"
done;
echo i = $i
echo a = ${#a[@]}
echo args = ${#args[@]}
echo $args
}
The output of this function is
$> doSomthing $'1\n2\n3\n4'
wc = 4
1
2
3
4
i = 4
a = 4
args = 1
1 2 3 4