eBash (Extended Bash) is a simple Bash preprocessor adding some syntactic sugar and math expressions.
- Download the script and give it execution rights:
chmod +x ./ebash.sh
- 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"
- Then execute the script using
ebash.sh
:
./ebash.sh test.esh
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:
- Directly executing .esh files:
./ebash.sh test.esh
- Transpiling .esh files into regular .sh files:
./ebash.sh test.esh test.sh
- 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)
Example:
i=1
$i++
echo "i = $i"
Outputs i = 2
Example:
a=${{ 2.5 * 6 + s(0) }} # 15
b=${{ 2^2 }} # 4
echo "The result is ${{ $a / $b }}"
Outputs The result is 3.75
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
function show_time(hours, minutes) {
echo "The time is $hours:$minutes."
}
show_time 12 30
Outputs The time is 12:30.
- 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