📄 shell.sgml
字号:
<refentry id="glib-Shell-related-Utilities"><refmeta><refentrytitle>Shell-related Utilities</refentrytitle><manvolnum>3</manvolnum><refmiscinfo>GLIB Library</refmiscinfo></refmeta><refnamediv><refname>Shell-related Utilities</refname><refpurpose>shell-like commandline handling.</refpurpose></refnamediv><refsynopsisdiv><title>Synopsis</title><synopsis>#include <glib.h>enum <link linkend="GShellError">GShellError</link>;#define <link linkend="G-SHELL-ERROR-CAPS">G_SHELL_ERROR</link><link linkend="gboolean">gboolean</link> <link linkend="g-shell-parse-argv">g_shell_parse_argv</link> (const <link linkend="gchar">gchar</link> *command_line, <link linkend="gint">gint</link> *argcp, <link linkend="gchar">gchar</link> ***argvp, <link linkend="GError">GError</link> **error);<link linkend="gchar">gchar</link>* <link linkend="g-shell-quote">g_shell_quote</link> (const <link linkend="gchar">gchar</link> *unquoted_string);<link linkend="gchar">gchar</link>* <link linkend="g-shell-unquote">g_shell_unquote</link> (const <link linkend="gchar">gchar</link> *quoted_string, <link linkend="GError">GError</link> **error);</synopsis></refsynopsisdiv><refsect1><title>Description</title><para></para></refsect1><refsect1><title>Details</title><refsect2><title><anchor id="GShellError">enum GShellError</title><programlisting>typedef enum{ /* mismatched or otherwise mangled quoting */ G_SHELL_ERROR_BAD_QUOTING, /* string to be parsed was empty */ G_SHELL_ERROR_EMPTY_STRING, G_SHELL_ERROR_FAILED} GShellError;</programlisting><para>Error codes returned by shell functions.</para><informaltable pgwide="1" frame="none" role="enum"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry><literal>G_SHELL_ERROR_BAD_QUOTING</literal></entry><entry>Mismatched or otherwise mangled quoting.</entry></row><row><entry><literal>G_SHELL_ERROR_EMPTY_STRING</literal></entry><entry>String to be parsed was empty.</entry></row><row><entry><literal>G_SHELL_ERROR_FAILED</literal></entry><entry>Some other error.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="G-SHELL-ERROR-CAPS">G_SHELL_ERROR</title><programlisting>#define G_SHELL_ERROR g_shell_error_quark ()</programlisting><para>Error domain for shell functions. Errors in this domain willbe from the <link linkend="GShellError">GShellError</link> enumeration. See <link linkend="GError">GError</link> for information onerror domains.</para></refsect2><refsect2><title><anchor id="g-shell-parse-argv">g_shell_parse_argv ()</title><programlisting><link linkend="gboolean">gboolean</link> g_shell_parse_argv (const <link linkend="gchar">gchar</link> *command_line, <link linkend="gint">gint</link> *argcp, <link linkend="gchar">gchar</link> ***argvp, <link linkend="GError">GError</link> **error);</programlisting><para>Parses a command line into an argument vector, in much the same waythe shell would, but without many of the expansions the shell wouldperform (variable expansion, globs, operators, filename expansion,etc. are not supported). The results are defined to be the same asthose you would get from a UNIX98 /bin/sh, as long as the inputcontains none of the unsupported shell expansions. If the inputdoes contain such expansions, they are passed throughliterally. Possible errors are those from the <link linkend="G-SHELL-ERROR-CAPS">G_SHELL_ERROR</link>domain. Free the returned vector with <link linkend="g-strfreev">g_strfreev</link>().</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>command_line</parameter> :</entry><entry> command line to parse</entry></row><row><entry align="right"><parameter>argcp</parameter> :</entry><entry> return location for number of args</entry></row><row><entry align="right"><parameter>argvp</parameter> :</entry><entry> return location for array of args</entry></row><row><entry align="right"><parameter>error</parameter> :</entry><entry> return location for error</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> <literal>TRUE</literal> on success, <literal>FALSE</literal> if error set</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-shell-quote">g_shell_quote ()</title><programlisting><link linkend="gchar">gchar</link>* g_shell_quote (const <link linkend="gchar">gchar</link> *unquoted_string);</programlisting><para>Quotes a string so that the shell (/bin/sh) will interpret thequoted string to mean <parameter>unquoted_string</parameter>. If you pass a filename tothe shell, for example, you should first quote it with thisfunction. The return value must be freed with <link linkend="g-free">g_free</link>(). Thequoting style used is undefined (single or double quotes may beused).</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>unquoted_string</parameter> :</entry><entry> a literal string</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> quoted string</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-shell-unquote">g_shell_unquote ()</title><programlisting><link linkend="gchar">gchar</link>* g_shell_unquote (const <link linkend="gchar">gchar</link> *quoted_string, <link linkend="GError">GError</link> **error);</programlisting><para>Unquotes a string as the shell (/bin/sh) would. Only handlesquotes; if a string contains file globs, arithmetic operators,variables, backticks, redirections, or other special-to-the-shellfeatures, the result will be different from the result a real shellwould produce (the variables, backticks, etc. will be passedthrough literally instead of being expanded). This function isguaranteed to succeed if applied to the result of<link linkend="g-shell-quote">g_shell_quote</link>(). If it fails, it returns <literal>NULL</literal> and sets theerror. The <parameter>quoted_string</parameter> need not actually contain quoted orescaped text; <link linkend="g-shell-unquote">g_shell_unquote</link>() simply goes through the string andunquotes/unescapes anything that the shell would. Both single anddouble quotes are handled, as are escapes including escapednewlines. The return value must be freed with <link linkend="g-free">g_free</link>(). Possibleerrors are in the <link linkend="G-SHELL-ERROR-CAPS">G_SHELL_ERROR</link> domain.</para><para>Shell quoting rules are a bit strange. Single quotes preserve theliteral string exactly. escape sequences are not allowed; not even\' - if you want a ' in the quoted text, you have to do somethinglike 'foo'\''bar'. Double quotes allow $, `, ", \, and newline tobe escaped with backslash. Otherwise double quotes preserve thingsliterally.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>quoted_string</parameter> :</entry><entry> shell-quoted string</entry></row><row><entry align="right"><parameter>error</parameter> :</entry><entry> error return location or NULL</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> an unquoted string</entry></row></tbody></tgroup></informaltable></refsect2></refsect1></refentry>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -