Skip to content
/ ebash Public

eBash (Extended Bash) is a simple Bash preprocessor that adds syntactic sugar and math expressions.

Notifications You must be signed in to change notification settings

k0marov/ebash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

ebash

eBash (Extended Bash) is a simple Bash preprocessor adding some syntactic sugar and math expressions.

Quick Start

  1. Download the script and give it execution rights:
chmod +x ./ebash.sh
  1. Write a Bash script using additional eBash syntax and give it an extension of .esh:

test.esh

function area(radius) { # named function arguments
	echo "${{pi*$radius^2}}" # syntax for math, pi is a preset constant
}
read -p "Please enter the circle radius: " radius 
echo "Area = `area $radius`" 
$radius++ # the increment operator
echo "If you increment the radius, the area would be = `area $radius`"
# syntax for math conditionals 
[[ $?{{ $radius > 3.5 }} ]] && echo "New radius is greater than 3.5" 
  1. Then execute the script using ebash.sh:
./ebash.sh test.esh

Docs

General

The script works as a preprocessor that transpiles .esh files to Bash-executable .sh files.

.esh files support special syntax for complex arithmetic operations using bc.

There are three ways of using ebash:

  1. Directly executing .esh files:
./ebash.sh test.esh 
  1. Transpiling .esh files into regular .sh files:
./ebash.sh test.esh test.sh 
  1. Directly executing .esh files by using a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix). For example, #!/usr/bin/ebash.
chmod +x test.esh 
./test.esh 

You need to copy ebash.sh into /usr/bin/ebash (or the path of your choice)

Features

Increment Operator

Example:

i=1
$i++
echo "i = $i" 

Outputs i = 2

Arithmetic Expressions

Example:

a=${{ 2.5 * 6 + s(0) }} # 15 
b=${{ 2^2 }} # 4 
echo "The result is ${{ $a / $b }}" 

Outputs The result is 3.75

Arithmetic Conditional Expressions

Example:

[[ $?{{s(pi/4) > 1/2}} ]] && echo "Sine of pi/4 is greater than 0.5" 
[[ $?{{pi > 4}} ]] && echo "Pi is greater than 4"

Outputs Sine of pi/4 is greater than 0.5

Named Function Arguments

function show_time(hours, minutes) {
	echo "The time is $hours:$minutes."
}
show_time 12 30

Outputs The time is 12:30.

TODO

  • increment operator $i++
  • complex arithmetic expressions ${{5/3 + 3^2 + sin(0)}}
  • complex arithmetic inequalities $?{{5/3 >= 2}}
  • directly executing the provided .esh file
  • transpiling to a file
  • specifying the output file path
  • validating the output file path
  • add more info to the docs
  • add support for the PI constant
  • validation of the input file argument
  • support for running with shebang
  • changing the shebang for the output file
  • checking if the output file already exists
  • add support for named function arguments
  • tests

About

eBash (Extended Bash) is a simple Bash preprocessor that adds syntactic sugar and math expressions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages