Blame docs/reference/glib/html/glib-Shell-related-Utilities.html

Packit ae235b
Packit ae235b
<html>
Packit ae235b
<head>
Packit ae235b
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Packit ae235b
<title>Shell-related Utilities: GLib Reference Manual</title>
Packit ae235b
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
Packit ae235b
<link rel="home" href="index.html" title="GLib Reference Manual">
Packit ae235b
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
Packit ae235b
<link rel="prev" href="glib-Hostname-Utilities.html" title="Hostname Utilities">
Packit ae235b
<link rel="next" href="glib-Commandline-option-parser.html" title="Commandline option parser">
Packit ae235b
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
Packit ae235b
<link rel="stylesheet" href="style.css" type="text/css">
Packit ae235b
</head>
Packit ae235b
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Packit ae235b
Packit ae235b
Packit ae235b
Top  | 
Packit ae235b
                  Description
Packit ae235b
Packit ae235b
Home
Packit ae235b
Up
Packit ae235b
Prev
Packit ae235b
Next
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Shell-related Utilities

Packit ae235b

Shell-related Utilities — shell-like commandline handling

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_shell_parse_argv ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gchar *
Packit ae235b
Packit ae235b
Packit ae235b
g_shell_quote ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gchar *
Packit ae235b
Packit ae235b
Packit ae235b
g_shell_unquote ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
enum
Packit ae235b
GShellError
Packit ae235b
Packit ae235b
Packit ae235b
#define
Packit ae235b
G_SHELL_ERROR
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Includes

Packit ae235b
#include <glib.h>
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Description

Packit ae235b

GLib provides the functions g_shell_quote() and g_shell_unquote()

Packit ae235b
to handle shell-like quoting in strings. The function g_shell_parse_argv()
Packit ae235b
parses a string similar to the way a POSIX shell (/bin/sh) would.

Packit ae235b

Note that string handling in shells has many obscure and historical

Packit ae235b
corner-cases which these functions do not necessarily reproduce. They
Packit ae235b
are good enough in practice, though.

Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b

g_shell_parse_argv ()

Packit ae235b
gboolean
Packit ae235b
g_shell_parse_argv (const gchar *command_line,
Packit ae235b
                    gint *argcp,
Packit ae235b
                    gchar ***argvp,
Packit ae235b
                    GError **error);
Packit ae235b

Parses a command line into an argument vector, in much the same way

Packit ae235b
the shell would, but without many of the expansions the shell would
Packit ae235b
perform (variable expansion, globs, operators, filename expansion,
Packit ae235b
etc. are not supported). The results are defined to be the same as
Packit ae235b
those you would get from a UNIX98 /bin/sh, as long as the input
Packit ae235b
contains none of the unsupported shell expansions. If the input
Packit ae235b
does contain such expansions, they are passed through
Packit ae235b
literally. Possible errors are those from the G_SHELL_ERROR
Packit ae235b
domain. Free the returned vector with g_strfreev().

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

command_line

Packit ae235b

command line to parse.

Packit ae235b
[type filename]
Packit ae235b
Packit ae235b
Packit ae235b

argcp

Packit ae235b

return location for number of args.

Packit ae235b
[out][optional]
Packit ae235b
Packit ae235b
Packit ae235b

argvp

Packit ae235b

return location for array of args.

Packit ae235b
[out][optional][array length=argcp zero-terminated=1][element-type filename]
Packit ae235b
Packit ae235b
Packit ae235b

error

Packit ae235b

return location for error.

Packit ae235b
[optional]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE on success, FALSE if error set

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_shell_quote ()

Packit ae235b
gchar *
Packit ae235b
g_shell_quote (const gchar *unquoted_string);
Packit ae235b

Quotes a string so that the shell (/bin/sh) will interpret the

Packit ae235b
quoted string to mean unquoted_string
Packit ae235b
. If you pass a filename to
Packit ae235b
the shell, for example, you should first quote it with this
Packit ae235b
function.  The return value must be freed with g_free(). The
Packit ae235b
quoting style used is undefined (single or double quotes may be
Packit ae235b
used).

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

unquoted_string

Packit ae235b

a literal string.

Packit ae235b
[type filename]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

quoted string.

Packit ae235b

[type filename]

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_shell_unquote ()

Packit ae235b
gchar *
Packit ae235b
g_shell_unquote (const gchar *quoted_string,
Packit ae235b
                 GError **error);
Packit ae235b

Unquotes a string as the shell (/bin/sh) would. Only handles

Packit ae235b
quotes; if a string contains file globs, arithmetic operators,
Packit ae235b
variables, backticks, redirections, or other special-to-the-shell
Packit ae235b
features, the result will be different from the result a real shell
Packit ae235b
would produce (the variables, backticks, etc. will be passed
Packit ae235b
through literally instead of being expanded). This function is
Packit ae235b
guaranteed to succeed if applied to the result of
Packit ae235b
g_shell_quote(). If it fails, it returns NULL and sets the
Packit ae235b
error. The quoted_string
Packit ae235b
 need not actually contain quoted or
Packit ae235b
escaped text; g_shell_unquote() simply goes through the string and
Packit ae235b
unquotes/unescapes anything that the shell would. Both single and
Packit ae235b
double quotes are handled, as are escapes including escaped
Packit ae235b
newlines. The return value must be freed with g_free(). Possible
Packit ae235b
errors are in the G_SHELL_ERROR domain.

Packit ae235b

Shell quoting rules are a bit strange. Single quotes preserve the

Packit ae235b
literal string exactly. escape sequences are not allowed; not even
Packit ae235b
\' - if you want a ' in the quoted text, you have to do something
Packit ae235b
like 'foo'\''bar'.  Double quotes allow $, `, ", \, and newline to
Packit ae235b
be escaped with backslash. Otherwise double quotes preserve things
Packit ae235b
literally.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

quoted_string

Packit ae235b

shell-quoted string.

Packit ae235b
[type filename]
Packit ae235b
Packit ae235b
Packit ae235b

error

Packit ae235b

error return location or NULL

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

an unquoted string.

Packit ae235b

[type filename]

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b

enum GShellError

Packit ae235b

Error codes returned by shell functions.

Packit ae235b
Packit ae235b

Members

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

G_SHELL_ERROR_BAD_QUOTING

Packit ae235b
Packit ae235b

Mismatched or otherwise mangled quoting.

Packit ae235b
Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

G_SHELL_ERROR_EMPTY_STRING

Packit ae235b
Packit ae235b

String to be parsed was empty.

Packit ae235b
Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

G_SHELL_ERROR_FAILED

Packit ae235b
Packit ae235b

Some other error.

Packit ae235b
Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

G_SHELL_ERROR

Packit ae235b
#define G_SHELL_ERROR g_shell_error_quark ()
Packit ae235b
Packit ae235b

Error domain for shell functions. Errors in this domain will be from

Packit ae235b
the GShellError enumeration. See GError for information on error
Packit ae235b
domains.

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Generated by GTK-Doc V1.27
Packit ae235b
</body>
Packit ae235b
</html>