Skip to content
Snippets Groups Projects
Commit 872cfcdf authored by Thomas Junier's avatar Thomas Junier
Browse files

added some of the most useful options (set and shopt)

parent e9185dda
Branches lite
No related tags found
No related merge requests found
No preview for this file type
......@@ -92,7 +92,10 @@
\usepackage{selnolig} % disable illegal ligatures
\fi
%% My own definitions
\newcommand{\eg}{\emph{e.g.}}
\newcommand{\ttit}[1]{\texttt{\itshape #1}}
\title{Bash Programming Reference}
\author{}
\date{}
......@@ -632,6 +635,8 @@ Words resulting from \emph{word splitting} (\ref{word-splitting}) and containing
A pattern expands to the list of matching filenames, if any; otherwise it
remains unchanged.
Several \textit{options} (\ref{options}) can modify this behaviour.
\hypertarget{quote-removal}{%
\subsection{Quote Removal}\label{quote-removal}}
......@@ -888,7 +893,7 @@ arguments with \emph{shell arithmetic} (\ref{shell-arithmetic}).
% TODO: mention that globbing occurs only if the RHS of == is unquoted.
% TODO: remind that expansion occurs (except W F)
\begin{tabular}{ll}
\begin{tabular}{lp{5cm}}
\textbf{expr} & \textbf{true iff} \\
\texttt{-e f} & \texttt{f} exists \\
\texttt{-f f} & \texttt{f} is a regular file \\
......@@ -903,6 +908,7 @@ arguments with \emph{shell arithmetic} (\ref{shell-arithmetic}).
\texttt{str} & \texttt{str} has nonzero length \\
\texttt{s == p} & \texttt{s} =/matches \texttt{p} \\
\texttt{s = p} & \texttt{s} =/matches \texttt{p} \\
\texttt{s =\~{} re} & \texttt{s} matches POSIX extended regular expression \ttit{re}, any matches and captures are stored in array \texttt{BASH\_REMATCH} \\
\texttt{s != p} & \texttt{s} $\neq$/doesn't match \texttt{p} \\
\texttt{s1 < s2} & \texttt{s1} sorts before \texttt{s2} (\texttt{>}: after) \\
\texttt{a1 -eq a2} & \texttt{a1} $=$ \texttt{a2} \\
......@@ -1145,6 +1151,40 @@ global)
\hypertarget{options}{%
\section{Options}\label{options}}
A selection of options useful for programming
\subsection{\texttt{set} Options}\label{opt-set}
The following options can be set with \texttt{set -\ttit{o}} (short
form) or \texttt{set -o \ttit{option}} (long form); they can also be set
with \texttt{shopt -s -o \ttit{option}}. To unset: \texttt{set
+\ttit{o}}, \texttt{set +o \ttit{option}}, or \texttt{shopt -u -o
\ttit{option}}, respectively.
\begin{tabular}{p{2.5cm}p{5.5cm}}
\texttt{-e}, \texttt{-o~errexit} & Exit immediately if a command returns nonzero status (the \href{https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html}{complete rules} are more complicated). \\
\texttt{-f}, \texttt{-o~noglob} & Do not peform filename expansion (\ref{filename-expansion}). \\
\texttt{-n}, \texttt{-o~noexec} & Read input but do not execute commands ("dry run"). \\
\texttt{-u}, \texttt{-o~nounset} & Treat unset parameters (other than \texttt{@} and \texttt{*}) during expansion (\ref{parameter-expansion}) as an error. \\
\texttt{-x}, \texttt{-o~xtrace} & Print a trace of commands (\eg{} for debugging). \\
\texttt{-B}, \texttt{-o~braceexpand} & Perform brace expansion (ON by default). \\
\texttt{-C}, \texttt{-o~noclobber} & Prevent redirection (\ref{redirections}) from overwriting files. \\
\end{tabular}
\subsection{\texttt{shopt} Options}\label{opt-shopt}
The following options can be set by \texttt{shopt -s \ttit{opt}}, and unset by
\texttt{shopt -u \ttit{opt}}.
\begin{tabular}{lp{6cm}}
\texttt{dotglob} & If set, globbing considers files with names starting in '\texttt{.}' (except '\texttt{.}' and '\texttt{..}', which never match globs) If unset, these files don't match. \\
\texttt{extglob} & Enables extended pattern matching (\ref{extended-glob}). \\
\texttt{failglob} & Patterns that fail to match during filename globbing (\ref{filename-expansion}) cause an error \\
\texttt{globstar} & During filename expansion (\ref{filename-expansion}), \texttt{**} recursively matches filenames into subdirectories (\texttt{**/}: only directories) \\
\texttt{nocaseglob} & Filename expansion (\ref{filename-expansion}) is case-insensitive \\
\texttt{nocasematch} & Pattern matching in \texttt{case} (\ref{case---in}) and \texttt{[[...]]} (\ref{dsb-cond}) is case-insensitive. \\
\texttt{nullglob} & Filename patterns (\ref{filename-expansion}) which match no files expand to the null string. \\
\texttt{xpg\_echo} & The \texttt{echo} builtin expands \texttt{\textbackslash}-escape sequences. \\
\end{tabular}
\hypertarget{references}{%
\section{References}\label{references}}
......@@ -1179,11 +1219,11 @@ global)
\begin{itemize}
\item \texttt{read x y \textless{} \textless(\ldots)} (use process substitution to set variables)
\item \texttt{\$(\textless{}\ file)} is a faster equivalent of \texttt{\$(cat\ file)}
\item using \texttt{trap} to ensure closing files and
cleaning up
\end{itemize}
\item
\texttt{f -o a1 a2} -- you can pass switches and options to functions
\item
regexps \texttt{{[}{[}\ \$var\ =\textasciitilde{}\ regexp\ {]}{]}}
\item
options: one section on i\texttt{set} and \texttt{shopt}, then
mention of affecting options in the other sections (e.g.,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment