Skip to content

Main content

Parsing: Shell Parameter Simple Default Split Tool

Split one restricted shell parameter default expansion ${NAME-word} or ${NAME:-word}, preserving empty-vs-unset semantics; excludes nested expansions, escapes and execution.

Loading tool…

Description

Split one restricted shell parameter default expansion ${NAME-word} or ${NAME:-word}, preserving empty-vs-unset semantics; excludes nested expansions, escapes and execution.

Shell token meaning depends on quote context, escape syntax, parameter expansion, and the particular shell. A literal split or escape decoder can inspect text without evaluating it. Recognizing a token does not execute a command or reproduce every rule of a complete shell parser.

Split one restricted shell parameter default expansion ${NAME-word} or ${NAME:-word}, preserving empty-vs-unset semantics; excludes nested expansions, escapes and execution.

When to use this tool

Use Parsing: Shell Parameter Simple Default Split when you need to inspect the supported literal shell-related token or escape without evaluating it.

How to use the tool and how it works

  1. Enter token. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read result. Expand result to inspect the returned fields.

Accept a simple parameter expansion with an ASCII variable name, operator - or :-, and a fallback without braces or line breaks. Return parameter, operator, literal fallback, and emptyUsesFallback=true only for :- inside result.1

Input fieldMeaning and unitsAccepted input
tokenComplete literal token in the grammar stated above.Required. Text. Implementation limit: 8192 Unicode code points and 16384 UTF-16 code units.
Output fieldInterpretationReturned shape
resultObject containing the calculated result members described below.Required. Object.
result.parameterParameterCalculated result member: string.
result.operatorOperatorCalculated result member: string.
result.fallbackFallbackCalculated result member: string.
result.emptyUsesFallbackEmpty Uses FallbackCalculated result member: boolean.
json
{
  "input": {
    "token": "${NAME:-default}"
  },
  "output": {
    "result": {
      "parameter": "NAME",
      "operator": ":-",
      "fallback": "default",
      "emptyUsesFallback": true
    }
  }
}

Limitations and assumptions

  • The operator is labeled rather than evaluated against an environment. Nested expansion, quoting semantics, command substitution, and a complete shell grammar are unsupported; no shell code is run.
  • Outputs are nested inside result. Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.

Alternative or Complementary methods

Use a shell-aware lexer or parser for quote context, concatenated words, nested expansions, and complete command syntax. Preserve untrusted text as data when its role is inspection.

References

  1. Calculation and input contract: parse/shell-parameter-simple-default-split — tool.io

Similar or alternative tools