cat_n_ls=$(ls | cat -n)
assigns ls | cat -n
to a variable. ls
lists filenames in the current directory. Which is then passed tocat -n
which numbers each line. echo "$cat_n_ls"
then displays the result. "$cat_n_ls"
has quotation marks to preserve newlines. The script above returns something similar to the following example:
1 file1.sh
2 file2.sh
3 file3.sh
4 file4.sh
5 file5.sh
6 file6.sh
7 file7.sh