I have an array named c. Its elements are filenames found in the current directory. How do I list them on their own line with a number before? For example:
1. aaa
2. filename2
3. bbb
4. asdf
The code I have now just prints each file on its own line. Like:
aaa
filename2
bbb
asdf
My code is below:
#!/bin/bash
c=( $(ls --group-directories-first $*) )
printf '%s\n' "${c[@]}"
c=( $(ls --group-directories-first $*) )will lead to problems if any of your files have whitespace in their names.c=( * ). This will create an array with all file names and is safe to use whatever characters are in the file names. This does approach, however, does not offer the--group-directories-firstfunctionality.