Word: expandable text that may contain variables, command substitutions, etc.
A word is composed of parts that are either literals or expansions. Quoting affects how expansions are performed.
Examples
# hello (literal)
%Word{
parts: [{:literal, "hello"}],
quoted: :none
}
# $USER (variable)
%Word{
parts: [{:variable, %Variable{name: "USER"}}],
quoted: :none
}
# "hello $USER" (double-quoted with expansion)
%Word{
parts: [
{:literal, "hello "},
{:variable, %Variable{name: "USER"}}
],
quoted: :double
}
# 'hello $USER' (single-quoted, no expansion)
%Word{
parts: [{:literal, "hello $USER"}],
quoted: :single
}
# $(echo test) (command substitution)
%Word{
parts: [
{:command_subst, [%Command{name: "echo", args: ["test"]}]}
],
quoted: :none
}
# $((1 + 2)) (arithmetic expansion)
%Word{
parts: [{:arith_expand, "1 + 2"}],
quoted: :none
}
# *.txt (glob pattern)
%Word{
parts: [{:glob, "*.txt"}],
quoted: :none
}
Summary
Types
@type quote_type() :: :none | :single | :double
@type t() :: %Bash.AST.Word{ meta: Bash.AST.Meta.t(), parts: [part()], quoted: quote_type() }