quick-bash is a micro-language that transcompiles to Bash.
It was built mainly for research purposes and the aim is to make Bash coding more readable and (hopefully) easier to remember.
For the fun of it!
Also, because most of us never remember how if-else conditionals and for loops are written in Bash.
Uses the Python lex-yacc implementation ply for tokenization and LALR parsing, as well as the pyparsing package for source code preprocessing.
(@exec 'date')
(@for a ls (@echo a (* 2 2)))
(@if-else (== 1 2) (@echo (@exec 'date')) (@exec 'ls'));
(@pipe (@echo 'hello') (@ssh host1))
(@comment 'this will be a comment in the output')
(@raw 'cat myfile.txt | gzip --best - > myfile.txt.gz')
(@let ARR (@range 1 10))
// [ 1 -eq 2 ]
(@-eq 1 2)
// [ 2 -gt 1 ]
(@-gt 2 1)
// [ 3 -ge 4 ]
(@-ge 3 4)
// [ 4 -lt 5 ]
(@-lt 4 5)
// [ 6 -le 8 ]
(@-le 6 8)
// [ 1 -ne 1 ]
(@-ne 1 1)
Python logical operators can be used for pre-calculated boolean output:
// false
(== 1 2)
// true
(> 2 3)
C++ style comments are supported:
// Single line comments start with // and will be omitted in the output
/* Multiline comments as well */
# Simple assignment
(@let A 'HELLO WORLD')
# Referencing a variable
(@echo (@var A))
# Export variable
(@export A 'HELLO WORLD')
Functions start with @
:
# Start with @
(@gzip 'myfile')
# Command-line parameters are passed with `~`
(@gzip ~9 'myfile')
# Long form options can be passed with ~~
(@grep ~~max-count 4 ~~regexp '[a-z][0-9]' a.txt)
# Logical expressions
(@eq? 1 2)
Python functions can be invoked and the return value used as a string:
# Start with :
(@let CURRENT_TIME (:datetime.datetime.utcnow))
(@let A_DATETIME (:datetime.datetime.strptime "2014-05-06" "%Y-%m-%d"))
- Documentation
- More examples
pip install ply argparse pyparsing