Display array contents on a new line

ksh
eg
arrayname=(1 2 3 4 5)

I'm trying to display the individual contents of an array on a new line without using a loop, using one line of code.

output
1
2
3
4
5

#!/bin/ksh
arrayname=(1 2 3 4 5)
echo ${arrayname
[*]} | tr " " "\n"
1 Like

Thanks, that exactly what I was after.

---------- Post updated at 12:57 PM ---------- Previous update was at 12:45 PM ----------

if an arrays contents where

array[0]="the quick"
array[1]="brown fox"
array[2]="etc etc"

How would be able to display the elements on individual lines?

Better way, using pure shell builtins and splitting on array elements:

printf "%s\n" "${ARRAY[@]}"
2 Likes