JCShell - Command line/script parsing

The input lines read from a script are processed in the following way:

  1. Lines ending with a backslash are continued in the next line. These are combined into a single logical line.
  2. Comment lines are identified and ignored. A comment line starts with a `#' character. The command character may be preceded by white space.
  3. Leading labels are identified and are removed. A line may start with a label. The first word in a line is recognized as a label if it ends with a colon.

The resulting lines either contain a control flow statement or they call some command. If the line starts with the keyword of a control flow statement, the rest of the line is split into words. These words are arguments to the control flow statement.

keyword words

A command specifier may be one of the following:

  1. A builtin command identifier: Most of these commands start with a slash (/). Try ? or help to list these commands. Commands can be abbreviated. Each syllable (separated by dashes) of a command name can be abbreviated separately. For example, abbreviations of the command "/list-vars" are: "/list-v", "/l-vars", or "/l-v". If the abbreviation is ambiguous, an error will be generated.
  2. A plugin command: If a plugin is selected, it offers additional commands specific to the plugin. Try ? or help to list these commands.
  3. If a plugin with nickname p is active, the shell checks also if there is a script file named "p-c.jcsh" in one of the directories listed by the ${path} variable. The path variable contains a semicolon separated list of directories.
  4. The command specifier cmd refers to a script if there is a file "cmd.jcsh" in one of the directories listed by the ${path} variable.
  5. If the command specifier starts with one of the strings "./", "../", or "/" then it refers to a script file with the same name.

White space splits a line into words. Strings enclosed in "..." and '...' become part of words. Characters with special meaning can be quoted using a backslash in strings. The backslash is removed only if applied to special characters. In other cases the character sequence remains unchanged.

Labels and control flow keyword's are not subject to variable evaluation. In strings enclosed in single quotes (''), variables are not evaluated. All other words may contain variable references.

Examples:

/set-var x1 Hello
/set-var x2 ${abc}                x2 has value "Hello"
/set-var x2 "${abc} ${abc}"       x2 has value "Hello Hello"
/set-var x2 '${abc}'"${abc}"      x2 has value "${abc}Hello"
/echo '\$\'\"' "\$\\\""           prints the following: \$'\"$\"

Related information