This page contains pointers to various shellcode tutorials located upon the internet, for various platforms.
Perhaps the most important document you can read is the classic piece by Aleph One's "Smashing the stack for fun and profit". This paper describes many things, including how to derive shellcode via a compiler.
In essence the technique is to write a small piece of C code to run a shell via execve then refine the output produced by the compiler until you have something you can use.
There are more advanced techniques via polymorphic engines which can be given a description of the code you wish to produce will generate a (seemingly) endless number of permuations of code with that effect. This used to be very common in the early days of Virus writing, but sadly seems to be on the decline these days.
99% of the time the shellcode used in different exploits is identical.
Other pieces worth reading include: