NAME

Proc::ShellSubset - parse a Bourne-shell subset into a tree (EXPERIMENTAL)

SYNOPSIS

use Proc::ShellSubset;
my $t = Proc::ShellSubset::parse('ls -l | wc -l > out', if => 1, while => 1);
if (ref $t eq 'ARRAY') { ... }                         # the tree
else { warn "$t->{error} at $t->{pos}\n" }            # outside the subset

DESCRIPTION

parse($string, %options) returns the parse tree of a shell one-liner (an array reference), or, when the string is outside the subset, a hash { error, pos, last, tree }: the reason, the position where parsing failed, the position after the last top-level ;, & or newline, and the part parsed so far. Proc::ShellSpawn runs the trees.

Options, each off by default: if, while (also until, break, continue), for, case, read, assign (commands with settings only), param_ops (${x:-w} and the like), brace (brace expansion), tilde_args (~ after NAME= in arguments), fdmulti (descriptor numbers of two or more digits), empty (accept an empty string), nocaret (reject ^), nopwd (reject $PWD), and check (a code reference returning a reason to reject).

The tree format and the grammar are described in the comments at the top of the module and in doc/parsers/shell-subset-spec.md. Proc::ShellSubset::Small is the same grammar with the options frozen; Proc::ShellSubset::Large accepts much more.

SEE ALSO

Proc::ShellSubset::Small, Proc::ShellSubset::Large, Proc::ShellSpawn, doc/README.md.