In bash, how can I print the first n elements of a list?
bash
n
For example, the first 10 files in this list:
FILES=$(ls)
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)
FILES=(*)