Shell Script for a newbie

Hello all,
I want to write a shell script to list the contents of a directory and number them and write them to a file.

For example, if I have a directory temp and the contents of the directory are alpha, beta and gamma. I want to write these filenames to a file "test" in a numbered manner.

#cd temp
#ls
alpha beta gamma

The output of test file should be,

  1. alpha
  2. beta
  3. gamma

The contents of the directory can vary, so I want to write a dynamic script. Please help

N=1
ls /temp/ | while read FILE
do
        echo "${N}. ${FILE}"
        N=$((N+1))
done > list-of-files

I though ls had such an option, but I couldn't find it!

ls | awk '{print NR ".", $1}' > test

Thank you very much!!!!

I was actually writing a shell script for my webpage and I needed something similar to this and it works fine now. Thank you again:D

Another way :

ls | cat -n

Jean-Pierre.

My first attempt was this, but it doesn't give the output required (which is a shame because it's simpler!)

Another is

ls | grep -n .
ls | sed = | sed 'N;s/\n/. /' >test

I know it's been covered a number of ways, but just to throw an extra answer in the mix you could use the oft forgotten nl (number line) command

root@bms-nycnm-srv02:/usr/local/isa/run# ls|nl
     1  BmsUI.mpid
     2  BmsUI.pid
     3  CORBAnameservice.mpid
     4  CORBAnameservice.pid
     5  CORBAnotificationservice.mpid
     6  CORBAnotificationservice.pid

and redirect at your leisure.