Suppose I want to make a shell environment to typeset examples of shell commands. I'd like to automate some details to remain consistent. For example, I need to automatically put a '$' at the beginning of the first line, so a piece of code like:
\begin{shell}
cat nothing > /dev/null
cat: nothing: No such file or directory
\end{shell}
would be typeset as if the code were written as:
$ cat nothing > /dev/null
cat: nothing: No such file or directory
This idea can be expanded. For example, the command line could be typeset differently from the command output, or I may want to intercept a final \ to indent the subsequent lines, and so on...
In other words, I would like to preprocess the verbatim content of the environment before passing it to the actual lstlisting environment.
Is this even possible? How to do it?

every listing lineoption may be helpful to get the $ at every line. – samcarter_is_at_topanswers.xyz Oct 06 '16 at 16:01$on every line, and not just the first line? – Teepeemm Oct 06 '16 at 16:06