Pike v8.0 release 1738

Method Process.split_quoted_string()


Method split_quoted_string

array(string) split_quoted_string(string s, bool|void nt_mode)

Description

Splits the given string into a list of arguments, according to common (i.e. /bin/sh-based) command line quoting rules:

  • Sequences of whitespace, i.e. space, tab, \n or \r, are treated as argument separators by default.

  • Single or double quotes (' or ") can be used around an argument to avoid whitespace splitting inside it. If such quoted strings are used next to each other then they get concatenated to one argument; e.g. a"b"'c' becomes a single argument abc.

  • Backslash (\) can be used in front of one of the space or quote characters mentioned above to treat them literally. E.g. x\ y is a single argument with a space in the middle, and x\"y is a single argument with a double quote in the middle.

  • A backslash can also be used to quote itself; i.e. \\ becomes \.

  • Backslashes in front of other characters are removed by default. However, if the optional nt_mode flag is set then they are retained as-is, to work better with Windows style paths.

  • Backslashes are treated literally inside quoted strings, with the exception that \" is treated as a literal " inside a "-quoted string. It's therefore possible to include a literal " in a "-quoted string, as opposed to '-quoted strings which cannot contain a '.