BashSpark
Loading...
Searching...
No Matches
BashSpark

BashSpark - A powerful C++ library for custom command execution.
BashSpark is a command-line tool inspired by the Bash shell that allows users to execute custom commands seamlessly and flexibly. It supports various command types and functionalities tailored for enhanced usability.

Key Features

  • Bash Inspiration: While it draws inspiration from the Bash shell, it introduces unique features and behaviors to enhance usability.
  • Custom Command Execution: Users can define and execute their own commands, enabling flexible scripting and automation.
  • Rich Functionality: Accommodates diverse user needs through various command types and execution options.

Bash-style Syntax Support

BashSpark supports a variety of Bash-style syntaxes including:

  • ${VARIABLE_NAME}
  • ${!VARIABLE_NAME}
  • $(command)
  • function function_name {...}

Note: Does not recognize semicolons or newlines generated by expansion. Example: $cmd where cmd="echo -n 1; echo -n 2" outputs 1; echo -n 2, not 12.

Unique Capabilities

  • Interprets escaped characters (e.g., \n for newline, \t for tab).
  • Supports Unicode code points:
    • \x for ASCII
    • \u for UTF-16
    • \U for UTF-32
  • Returns shell_status::SHELL_ERROR_BAD_ENCODING for invalid code points.

Different Behavior from Bash

  • No requirement for spaces around '(', '[', '{', '}', ']' and ')'.
  • Both ( and [ are always interpreted, e.g., "echo }" works while "echo \\}" works in both.
  • Supports empty commands with valid syntax like ";;;".
  • Does not support improved test syntax [[...]].
  • Normal tests support ||, && and parentheses (...).
  • Arithmetic using (()) is not supported; use the math command instead.
  • Variable assignments using variable=value are not supported; use setenv and setvar commands.
  • Function definition syntax function_name(){...} is not supported; use fcall function_name <args>.

Command Management

Commands are instantiated from the bs::command class and managed within the shell to ensure safe and reliable command execution by preventing security holes and handling errors gracefully.

Shell Depth

The parser has a limit for depth set by std::size_t bs::shell::MAX_DEPTH, defaulting to 16. Users can modify this value and rebuild the project if necessary. The following conditions increase depth:

  • Parsing subblocks like "(...)" and "{...}"
  • Parsing subcommands like "$(...)"
  • Command eval (new shell starts a new depth).
  • Keywords like "if", "elif", "for", "while", "until".

Parsing variables ${...}, tests [...], and keywords like "then", "fi", "else", "do", "done" do not increase depth.

Known Issues

Current implementation attempts to prevent SIGSEGV. The shell execution does not throw exceptions except for std::bad_alloc or exceptions from provided streams. All errors listed on bs::shell_status are notified through stderr with the last command error code, including syntax errors and depth limit errors.

Other limitations:

  • Shell arguments are restricted to 19 digits due to std::uint64_t range.

Other documentation