You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ad5001 573d2da85e
First commit!
11 months ago
example First commit! 11 months ago
README.md First commit! 11 months ago
oop.sh First commit! 11 months ago

README.md

BashOOP

This idea was inspired from https://stackoverflow.com/a/40981277 in order to be adapted into making a proper OOP with constructors, properties and namespace system for bash.

Reference:

  • .shn: SHell Namespace
  • .shc: SHell Class

Example syntax:

Declaring objects.

script.sh: This is the main script which will use our objects.

. $OOP_ROOT/oop.sh # Import library.

importNamespace Example.shn

Example.Object t "Test"

Example.shn: This file declares our namespace and all the objects within it.

# Namespace declaration.
namespace Example
# If namespace is set to null (no argument), then the object will be declared globally.
# Otherwise, the object will be declared within the namespace.

# Object declaration, from class name to file name.
class Object "Object.shc"

Object.shc: This file will contain the object code.

# Property declaration
property Object.name

# Optional constructor.
Object.constructor() {
    Object.name = $1
}

# Example function
Object.print() {
    echo "Example OOP from $($this.name)!"
}