\section{KShell Namespace Reference}
\label{namespaceKShell}\index{KShell@{KShell}}
Provides some basic POSIX shell and bash functionality.  


\subsection*{Enumerations}
\begin{CompactItemize}
\item 
enum {\bf Options} \{ {\bf No\-Options} =  0, 
{\bf Tilde\-Expand} =  1, 
{\bf Abort\-On\-Meta} =  2
 \}
\item 
enum {\bf Errors} \{ {\bf No\-Error} =  0, 
{\bf Bad\-Quoting}, 
{\bf Found\-Meta}
 \}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
KDECORE\_\-EXPORT {\bf QString\-List} {\bf split\-Args} (const {\bf QString} \&cmd, int flags=0, int $\ast$err=0)
\item 
KDECORE\_\-EXPORT {\bf QString} {\bf join\-Args} (const {\bf QString\-List} \&args)
\item 
KDECORE\_\-EXPORT {\bf QString} {\bf join\-Args\-DQ} (const {\bf QString\-List} \&args)
\item 
KDECORE\_\-EXPORT {\bf QString} {\bf join\-Args} (const char $\ast$const $\ast$argv, int argc=-1)
\item 
KDECORE\_\-EXPORT {\bf QString} {\bf tilde\-Expand} (const {\bf QString} \&path)
\item 
KDECORE\_\-EXPORT {\bf QString} {\bf home\-Dir} (const {\bf QString} \&user)
\end{CompactItemize}


\subsection{Detailed Description}
Provides some basic POSIX shell and bash functionality. 

\begin{Desc}
\item[See also:]{\bf KString\-Handler}{\rm (p.\,\pageref{classKStringHandler})} \end{Desc}




\subsection{Enumeration Type Documentation}
\index{KShell@{KShell}!Options@{Options}}
\index{Options@{Options}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf KShell::Options}}\label{namespaceKShell_a12}


Flags for {\bf split\-Args()}{\rm (p.\,\pageref{namespaceKShell_a6})}. 

\begin{Desc}
\item[Enumeration values: ]\par
\begin{description}
\index{TildeExpand@{TildeExpand}!KShell@{KShell}}\index{KShell@{KShell}!TildeExpand@{TildeExpand}}\item[{\em 
Tilde\-Expand\label{namespaceKShell_a12a1}
}]Perform tilde expansion. \index{AbortOnMeta@{AbortOnMeta}!KShell@{KShell}}\index{KShell@{KShell}!AbortOnMeta@{AbortOnMeta}}\item[{\em 
Abort\-On\-Meta\label{namespaceKShell_a12a2}
}]Bail out if a non-quoting and not quoted shell meta character is encoutered. 

Meta characters are the command separators {\tt semicolon} and {\tt ampersand}, the redirection symbols {\tt less-than}, {\tt greater-than} and the {\tt pipe} {\tt symbol}, the grouping symbols opening and closing {\tt parens} and {\tt braces}, the command substitution symbol {\tt backquote}, the generic substitution symbol {\tt dollar} (if not followed by an apostrophe), the wildcards {\tt asterisk} and {\tt question} {\tt mark}, and the comment symbol {\tt hash} {\tt mark}. Additionally, a variable assignment in the first word is recognized. \end{description}
\end{Desc}



Definition at line 38 of file kshell.h.\index{KShell@{KShell}!Errors@{Errors}}
\index{Errors@{Errors}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf KShell::Errors}}\label{namespaceKShell_a13}


Status codes from {\bf split\-Args()}{\rm (p.\,\pageref{namespaceKShell_a6})}. 

\begin{Desc}
\item[Enumeration values: ]\par
\begin{description}
\index{NoError@{NoError}!KShell@{KShell}}\index{KShell@{KShell}!NoError@{NoError}}\item[{\em 
No\-Error\label{namespaceKShell_a13a3}
}]Success. \index{BadQuoting@{BadQuoting}!KShell@{KShell}}\index{KShell@{KShell}!BadQuoting@{BadQuoting}}\item[{\em 
Bad\-Quoting\label{namespaceKShell_a13a4}
}]Indicates a parsing error, like an unterminated quoted string. \index{FoundMeta@{FoundMeta}!KShell@{KShell}}\index{KShell@{KShell}!FoundMeta@{FoundMeta}}\item[{\em 
Found\-Meta\label{namespaceKShell_a13a5}
}]The Abort\-On\-Meta flag was set and a shell meta character was encoutered. \end{description}
\end{Desc}



Definition at line 62 of file kshell.h.

\subsection{Function Documentation}
\index{KShell@{KShell}!splitArgs@{splitArgs}}
\index{splitArgs@{splitArgs}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString\-List} KShell::split\-Args (const {\bf QString} \& {\em cmd}, int {\em flags} = {\tt 0}, int $\ast$ {\em err} = {\tt 0})}\label{namespaceKShell_a6}


Splits {\tt cmd} according to POSIX shell word splitting and quoting rules. 

Can optionally perform tilde expansion and/or abort if it finds shell meta characters it cannot process.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cmd}]the command to split \item[{\em flags}]operation flags, see Options \item[{\em err}]if not NULL, a status code will be stored at the pointer target, see Errors \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]a list of unquoted words or an empty list if an error occurred \end{Desc}


Definition at line 65 of file kshell.cpp.

References Abort\-On\-Meta, Bad\-Quoting, Found\-Meta, home\-Dir(), QString::is\-Empty(), QChar::is\-Space(), No\-Error, Tilde\-Expand, and QChar::unicode().

Referenced by KApplication::invoke\-Mailer().\index{KShell@{KShell}!joinArgs@{joinArgs}}
\index{joinArgs@{joinArgs}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KShell::join\-Args (const {\bf QString\-List} \& {\em args})}\label{namespaceKShell_a7}


Quotes and joins {\tt args} together according to POSIX shell rules. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em args}]a list of strings to quote and join \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]a command suitable for shell execution \end{Desc}


Definition at line 257 of file kshell.cpp.

References QString::append(), QString::is\-Empty(), and QString::replace().\index{KShell@{KShell}!joinArgsDQ@{joinArgsDQ}}
\index{joinArgsDQ@{joinArgsDQ}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KShell::join\-Args\-DQ (const {\bf QString\-List} \& {\em args})}\label{namespaceKShell_a8}


Same as above, but \$'' is used instead of '' for the quoting. 

The output is suitable for {\bf split\-Args()}{\rm (p.\,\pageref{namespaceKShell_a6})}, bash, zsh and possibly other bourne-compatible shells, but not for plain sh. The advantage is, that control characters (ASCII less than 32) are escaped into human-readable strings.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em args}]a list of strings to quote and join \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]a command suitable for shell execution \end{Desc}


Definition at line 311 of file kshell.cpp.

References QString::append(), QString::is\-Empty(), and QString::unicode().\index{KShell@{KShell}!joinArgs@{joinArgs}}
\index{joinArgs@{joinArgs}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KShell::join\-Args (const char $\ast$const $\ast$ {\em argv}, int {\em argc} = {\tt -1})}\label{namespaceKShell_a9}


Quotes and joins {\tt argv} together according to POSIX shell rules. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em argv}]an array of c strings to quote and join. The strings are expected to be in local-8-bit encoding. \item[{\em argc}]maximal number of strings in {\tt argv}. if not supplied, {\tt argv} must be null-terminated. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]a command suitable for shell execution \end{Desc}


Definition at line 283 of file kshell.cpp.

References QString::append(), QString::is\-Empty(), QString::length(), QString::replace(), and QString::unicode().\index{KShell@{KShell}!tildeExpand@{tildeExpand}}
\index{tildeExpand@{tildeExpand}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KShell::tilde\-Expand (const {\bf QString} \& {\em path})}\label{namespaceKShell_a10}


Performs tilde expansion on {\tt path}. 

Interprets \char`\"{}$\sim$/path\char`\"{} and \char`\"{}$\sim$user/path\char`\"{}.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em path}]the path to tilde-expand \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]the expanded path \end{Desc}


Definition at line 355 of file kshell.cpp.

References QString::find(), home\-Dir(), and QString::is\-Null().

Referenced by KStandard\-Dirs::add\-KDEDefaults().\index{KShell@{KShell}!homeDir@{homeDir}}
\index{homeDir@{homeDir}!KShell@{KShell}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KShell::home\-Dir (const {\bf QString} \& {\em user})}\label{namespaceKShell_a11}


Obtain a {\tt user's} home directory. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em user}]The name of the user whose home dir should be obtained. An empty string denotes the current user. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The user's home directory. \end{Desc}


Definition at line 369 of file kshell.cpp.

References QFile::decode\-Name().

Referenced by split\-Args(), and tilde\-Expand().