node-bash is an interpreted language written using JavaScript.
- dynamic typing [ courtsey of JS ].
- if, if else, while control structures.
- functions. [ recursion is also supported ]
- piping similar to bash.
To run the language, you must need nodejs.
you can run scripts by executing following script. node node-bash.js < filename >
and, not, or, if, else, while, funct, |, =, <, >, <=, >=, !=, ==
simple assignment will create variable in the current scope if does not exist.
a = 10;
#or
a = "Hello world";
#or
a = 1 + 2;
The language supports following operations.
- addition ( + )
- subtraction ( - )
- multiplication ( * ) and division ( / )
- power ( ^ )
- boolean operations using >, <, <=, >=, !=, ==, and, not, or.
- function call
- piping ( | )
you can define a function using funct keyword.
funct main(){
print( "Hello world" );
}
You can use piping similar to unix piping to pass output of one expression to other.
a = "Good morning";
a | b;
print( b );
#or
funct generateData(){
pipe( "This is node-bash lang" );
}
generateData() | a;
print(a);
source of the pipe statement must be an expression or anything which generates a value but the destination must always be a variable or a function call. Functions can pipe data using pipe built in function.
Following are the builtin functions supported by the languge.
- print( data );
- extractString( src, string_to_be_extracted ); # returns a string.
- split( delim );
- index( array, index ); # returns element at the given index.
- len( array ) # returns the length of the array.
funct fibo( n ){
if( n == 0 ){
return 0;
}
if( n == 1 ){
return 1;
}
else{
return fibo( n - 2 ) + fibo( n - 1 );
}
}
print( fibo(8) );
# addition
a = 1 + 2;
# multiplication
a = 1 * 2 * 4;
#division
a = 4 / 2;
# exponantiation
a = 4 ^ 2;
# subtraction
a = 4 - 2;
funct getData(){
pipe( "Good Morning" );
pipe( "Bad Morning" );
pipe( "Hello Good Morning" );
}
funct filter( out ){
lines = split( out, "\n" );
i = 0;
length = len( lines );
while( i < length ){
data = extractString( index( lines, i ), "Good" );
if( data == "Good" ){
pipe( index( lines, i ) );
}
i = i + 1;
}
}
getData() | filter() | output;
print( output );