Are you trying to achieve something like this?
% http://tex.stackexchange.com/questions/88564/how-can-i-add-borders
\documentclass[border=5,preview]{standalone}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
frame=single
}
\begin{document}
\begin{lstlisting}
g@g0001:~$ cd Desktop
g@g0001:~/Desktop$ cat script.sh
#!/bin/bash
echo $1 `date`
g@g0001:~/Desktop$ ./script.sh "hello"
hello Wed Dec 19 06:30:49 CET 2012
g@g0001:~/Desktop$ ./script.sh "`ls -la`"
total 244 drwxr-xr-x 2 g g 4096 2012-12-19 06:29
. drwxr-xr-x 34 g g 4096 2012-12-19 06:23
.. -rwxr-xr-x 1 g g 314 2012-11-24 12:06
25332.txt -rw------- 1 g g 1038 2008-01-15 18:59
Makefile -rw-r--r-- 1 g g 227981 2011-09-06 10:37
.pdf -rwxrwxrwx 1 g g 29 2012-12-18 18:16
script.sh Wed Dec 19 06:31:18 CET 2012
\end{lstlisting}
\end{document}
Here, the frame was achieved with the frame
option with value single
. The default value is none
. You can choose from other values: leftline
, topline
, bottomline
, lines
, or shadowbox
. Also, you don't need to put your listings inside \begin{ttfamily}...\end{ttfamily}
as this can be set by the option basicstyle
. The font styles can be achieved through options among others basicstyle
, keywordstyle
, numberstyle
, identifierstyle
, commentstyle
, etc. You can set these and more.
Consult the listings
manual (specifically Section 4.6 and 4.11) by clicking on this link or by entering texdoc listings
in your terminal. For a full set of frame options, see Section 4.11.