utils/bash/bash_parser library

Classes

AssignmentParts
Parsed variable assignment (name=value).
BashToken
A parsed bash token.
CommandList
Command list (connected by &&, ||, ;, &).
CommandListEntry
An entry in a command list: a pipeline plus the operator that follows it.
CommandSecurityAnalysis
Security analysis of a command.
HeredocInfo
Heredoc information.
Pipeline
Pipeline (connected by |).
Redirect
Redirect representation.
SimpleCommand
Simple command representation.

Enums

BashTokenType
Bash token types.
CommandCategory
Command category for security / display.
ListOperator
List operator between pipelines.
RedirectType
SecurityRiskLevel
Risk level.

Functions

analyzeCommandSecurity(String input) CommandSecurityAnalysis
Analyze a command for security risks.
classifyCommand(String command) CommandCategory
Classify a command into a CommandCategory.
computeRiskLevel(CommandSecurityAnalysis a) SecurityRiskLevel
Compute risk level from analysis.
detectDangerousPatterns(String command) List<String>
Detect dangerous patterns in a command and return descriptions of each.
extractCdTarget(String command) String?
Extract the target directory from a cd command.
extractCommands(String input) List<SimpleCommand>
Extract all simple commands from a command string.
extractExecutable(String input) String?
Extract the primary executable from a command string.
extractHeredocs(String input) List<HeredocInfo>
Extract heredoc information from a command string.
hasProcessSubstitution(String command) bool
Detect if a command uses process substitution <() or >().
interpretExitCode(int exitCode, String command) String
Provide a semantic interpretation of an exit code for a given command.
isDirectoryChangingCommand(String command) bool
Check if a command modifies the working directory.
isHeredocSafe(HeredocInfo heredoc) bool
Check if a heredoc is safe (no command substitution or dangerous variable expansion).
isValidAssignment(String assignment) bool
Validate environment variable assignments.
parseAssignment(String assignment) AssignmentParts?
Parse environment variable name and value from an assignment string.
parseCommand(String input) CommandList
Parse a command string into a CommandList.
shellQuote(String input) String
Quote a string for safe shell usage.
shellQuoteArgs(List<String> args) String
Quote a list of arguments and join them with spaces.
stripAnsiCodes(String input) String
Strip ANSI escape codes from output.
tokenizeBash(String input) List<BashToken>
Tokenize a bash command string into a list of BashTokens.
truncateOutput(String output, {int maxLines = 1000, int maxChars = 100000}) String
Truncate command output to a maximum number of lines and/or characters.