/mybash

A very minimalistic programming language built with Rust

Primary LanguageRust

MyBash

A very minimalistic programming language built with Rust

My Bash

Example

# mybash ./foo.mb bar baz
# This is a comment
# If statments and exper evaluation
if $1 = "bar"
do echo "I got bar"
else
do echo "I got baz"
endif

# Variables
name: str = "Jone"
age: int = 31
is_awesome: bool = true
math_expr = 12 / 2 + 1 # 7
echo math_expr

Examples

Variable declaration with basic if statment
# mybash script.mb

age: int = 30
echo age
if age > 40
do echo "I am old"
else
do echo "I am still young"
endif

Output

30
I am still young
Access positional arguments and echo it to the stdout
# mybash script_5.mb me
echo $1

if $1 == 'me'
do echo "Hello, Ahmed"
else
do echo "Hi, :) ${1}"
endif

Output

Ahmed
Hi, :) Ahmed ✋
Access evn variables (with comments)
# Echo env variables to the stdout
# example: mybash ./sript_6.mb foo bar baz
echo $PATH
echo $PWD # Current working directory

echo $0  # Should display the script name  (script_6.mb)
echo $1  # Should display the first arg (foo)
echo $2  # Should display the second arg (bar)
Evaluate math expressions and echo it to the stdout
res: int = (12 + 12) / 4
echo "(12 + 12) / 4 ⏬"
echo res

Output

(12 + 12) / 4 ⏬
6
Variable expansion with echo statments
name: str = "Jone"

echo "Hello, $name 🙌"

echo "PATH = ${PATH}"
echo "HOME = $HOME"
echo "PWD = $PWD"
echo "HOSTNAME = $HOSTNAME"
echo "HOSTTYPE = $HOSTTYPE"
Variable concatenation
f_name: str = "Jone"
l_name: str = "doe"

full_name: str = "${f_name} ${l_name}"

echo "My full name is $full_name"

Output

My full name is Jone doe
Read stdin
name: string = input("What is your name? ")
age: string = input("What is your age? ")
addr: string = input("What is your address? ")

echo "My name is $name"
echo "My age is $age"
echo "I live in $addr"