[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]
string::token::shell(n) 1.2 tcllib "Text and string utilities"
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
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.
- ::string token shell ?-indices? ?-partial? ?--? string
This command parses the input string under the assumption of it following basic sh-syntax. The result of the command is a list of words in the string. An error is thrown if the input does not follow the allowed syntax. The behaviour can be modified by specifying any of the two options -indices and -partial.
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.
- single-quoted word
A single-quoted word begins with a single-quote character, i.e. ' (ASCII 39) followed by zero or more unicode characters not a single-quote, and then closed by a single-quote.
The word must be followed by either the end of the string, or whitespace. A word cannot directly follow the word.
- double-quoted word
A double-quoted word begins with a double-quote character, i.e. " (ASCII 34) followed by zero or more unicode characters not a double-quote, and then closed by a double-quote.
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.
- unquoted word
Unquoted words are not delimited by quotes and thus cannot contain whitespace or single-quote characters. Double-quote and backslash characters can be put into unquoted words, by quting them like for double-quoted words.
Whitespace is any unicode space character. This is equivalent to string is space, or the regular expression \\s.
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. Please also report any ideas for enhancements you may have for either package and/or documentation.