The following script outputs a numbered list of items.
#!/bin/bash
menu=( $(ls ${HOME}) )
i=0
for m in ${menu[@]}
do
echo "$(( i++ ))) $m"
done
The result:
0) item
1) item
2) item
3) item
I would like to split that list into multiple columns so more data fits on one page. Simply piping to column echo "$(( i++ ))) $m" | column still results in a single column only now every line begins with 0) followed by the item listed.
The answers given in How to output an array's content in columns in BASH work as far as making multiple columns of output.
menu=( $(ls $HOME) )
echo " ${menu[@]/%/$'\n'}" | column
But because the array is quoted, using the bash arithmetic method i=0; echo "$(( i++ ))" doesn't work for numbering as the only number output is the first 0.
My question is: How can I output the data from an array into an numbered list of multiple columns?
0) item 4) item 8) item
1) item 5) item 9) item
2) item 6) item 10) item
3) item 7) item 11) item
lsand quote everything. Anyway looks like you are actually looking simply forselect file in "$HOME"/*