string::token::shell(3tcl) | Text and string utilities | string::token::shell(3tcl) |
string::token::shell - Parsing of shell command line
package require Tcl 8.5
package require string::token::shell ?1.2?
package require string::token ?1?
package require fileutil
::string token shell ?-indices? ?-partial? ?--? string
This package provides a command which parses a line of text using basic sh-syntax into a list of words.
The complete set of procedures is described below.
Note that the length of the word as given by the indices can differ from the length of the word found in the last element of the tuple. The indices describe the words extent in the input, including delimiters, intra-word quoting, etc. whereas for the actual text of the word delimiters are stripped, intra-word quoting decoded, etc.
The possible token types are
The basic shell syntax accepted here are unquoted, single- and double-quoted words, separated by whitespace. Leading and trailing whitespace are possible too, and stripped. Shell variables in their various forms are not recognized, nor are sub-shells. As for the recognized forms of words, see below for the detailed specification.
The word must be followed by either the end of the string, or whitespace. A word cannot directly follow the word.
Contrary to single-quoted words a double-quote can be embedded into the word, by prefacing, i.e. escaping, i.e. quoting it with a backslash character \ (ASCII 92). Similarly a backslash character must be quoted with itself to be inserted literally.
Whitespace may occur before the first word, or after the last word. Whitespace must occur between adjacent words.
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category textutil of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.
bash, lexing, parsing, shell, string, tokenization
Text processing
1.2 | tcllib |