I have an array in bash...say, my_array:
my_array={1,2,3,4}
I need two requirements for this: 1) Print all of these elements on the same line, and 2) Separate each element with a tab.
When I print the elements out, here is what the output should be:
1 2 3 4
With each "gap" in between the elements being a tab.
Any suggestions on how to do this would be appreciated. Thank you.
EDIT Here's what I've tried so far:
1) I know I can print out an array on the same line as so:
echo {my_array[*]}
2) To get the desired tabs, I've tried making a variable with just a tab inside, and adding it to my array between each element:
temp=" "
for(...)
do
((my_array+=$i))
((my_array+=$temp))
done
This, however, gives me an error.
EDIT 2 Solution provided by Inan
This works:
printf '%s\t' "${my_array[@]}"
However, a couple things here; how would I delete the last tab, after the very last element?