question about about Shell programming

1.if [ "$1" ]
2.then
3.        # save the number of args and first argument in variables.
4.        num_args=$#
5.        id="$1"
6.        echo "$id"
7.        #echo "$1" > crapfile.txt
8.        echo `sed 's/\*/'\*'/g' < crapfile.txt`

Above is a partial code.I would like to ask:
at line 1: what is $1 how it works
at line 4: what is $#
at line 8: what does it try to do.
I am new to shell programming. Can anyone out there explain it to me. Thanks

For basic usage like this you really should look at the appropriate man pages.
I should begin with google on "ksh scripting" assuming you're using ksh.

Regards