答案1
这是一种改进方法——添加一些缺失的关键词,使用一些颜色,并将其全部放入单色字体中。
\documentclass[border=5mm]{standalone}
\usepackage{listings}
\RequirePackage{xcolor}
\definecolor{textblue}{rgb}{.2,.2,.7}
\definecolor{textred}{rgb}{0.54,0,0}
\newcommand\basher{\lstset{
language=Bash,
basicstyle=\ttfamily,
keywordstyle=\color{textblue},
commentstyle=\color{textred},
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=\parindent,
showstringspaces=false,
morekeywords={rm, sudo}
}}
\lstnewenvironment{shell}[1][]{\basher\lstset{#1}}{}
\begin{document}
\begin{shell}
sudo ./compromise.sh # install a compromised tcc
cd /tmp
rm -rf tcctmp
\end{shell}
\end{document}
应该产生如下结果:
我在建议的环境中添加了可选参数,shell
允许您像这样放入标题和标签:
\begin{shell}[caption=demo.sh, label={bashge2}]
sudo ./compromise.sh # install a compromised tcc
cd /tmp
rm -rf tcctmp
\end{shell}