Q:

In bash, how can I print the first n elements of a list?

In bash, how can I print the first n elements of a list?
For example, the first 10 files in this list:
FILES=$(ls)

UPDATE: I forgot to say that I want to print the elements on one line, just like when you print the whole list with echo $FILES.

A:

FILES=(*)
echo "${FILES[@]:0:10}"

Should work correctly even if there are spaces in filenames.
FILES=$(ls) creates a string variable. FILES=(*) creates an array. See this page for more examples on using arrays in bash. (thanks lhunath)

A:

FILE="$(ls | head -1)"

Handled spaces in filenames correctly too when I tried it.

A:

Why not just this to print the first 50 files:
ls -1 | head -50

