WARNING: IN PROGRESS
Bash Scripting is a simple programming language that compiles to Bash.
- More tests
- Syntax checking
- Support for expressions in
if
,while
andfor in
statements. - Pretty printing output script
bs /path/to/file.bs
bs -script /path/to/file.bs
The syntax of bs is C-based (derived from C programming language). If you have learned C, Java, C++ or JavaScript, bs is quite easy for you.
// This is a comment about your "code".
print("foo")
a = 1
b = "string"
c = array(1, 2, "str", true, false)
d = c[2]
a = 1 + 2
b = a * 7
c = concat("Con", "cat")
d = c + b
output = ls()
ex = exists("file.txt")
a = 3;
if a > 2 {
println("Yes")
} else if (a == 2) {
println("No")
}
list = array(1, 2, 3)
for i in list {
println(i)
}
n = 0
i = 0
j = 1
while n < 60 {
k = i + j
i = j
j = k
n = n + 1
println(k)
}
v1 = "Global V1"
v2 = "Global V2"
func foo(p) {
v1 = concat("Local ", p)
v2 = "V3 Modified."
}
foo("Var")
func fibonacci(num) {
if num == 0 {
return 0
} else if num == 1 {
return 1
} else {
return fibonacci(num - 2) + fibonacci(num - 1)
}
}
println(fibonacci(8))
import("./path/to/module/foo")
foo.function()
Prints a text string to console without a newline.
Prints a text string to console with a new line.
Runs command from path through the bash shell.
Put rawStatement
into compiled code for Bash.
Concatenates the given arguments and returns a string.
Returns an array of the given arguments.
Converts an array into a string so it can be passed as a function argument.
arr = array(1, 2, 3)
foo(pack(arr))
Returns an array from a string if the value was a packed array.
func foo(arr) {
a = unpack(arr)
return a[2]
}
go test
go test -coverprofile=coverage.out; go tool cover -html=coverage.out -o=coverage.html
open coverage.html
This project was inspired by Batsh.
Copyright 2015 Richard Allinson
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.