You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2015/04/30 10:02:14 UTC
[3/4] karaf git commit: [manual] add doc about expressions in the
shell
[manual] add doc about expressions in the shell
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/4aeed786
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/4aeed786
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/4aeed786
Branch: refs/heads/master
Commit: 4aeed7861244fb9d0548f7ad3987968d47fdf491
Parents: 9b65560
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Apr 30 09:49:50 2015 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Apr 30 09:50:17 2015 +0200
----------------------------------------------------------------------
.../main/webapp/developers-guide/scripting.conf | 75 ++++++++++++++++++++
manual/src/main/webapp/users-guide/console.conf | 11 +++
2 files changed, 86 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/4aeed786/manual/src/main/webapp/developers-guide/scripting.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/developers-guide/scripting.conf b/manual/src/main/webapp/developers-guide/scripting.conf
index afe2135..9fce440 100644
--- a/manual/src/main/webapp/developers-guide/scripting.conf
+++ b/manual/src/main/webapp/developers-guide/scripting.conf
@@ -36,6 +36,79 @@ The {{$.context}} access the context variables in the current session.
We access to the {{bundle}} variable (an array containing all bundles), and we want to display the bundle location for
the bundle at the index 1 in the bundle array.
+h2. Expressions
+
+The shell has a built-in expression parser. Expressions must be enclosed with the {{%(...)}} syntax.
+
+Examples:
+{code}
+karaf@root()> %(1+2)
+3
+karaf@root()> a = 0
+0
+karaf@root()> %(a+=1)
+1
+karaf@root()> %(a+=1)
+2
+karaf@root()> b=1
+1
+karaf@root()> %(SQRT(a^2 + b^2))
+1.7320508
+{code}
+
+h3. Mathematical Operators
+|| Operator || Description ||
+| + | Additive operator |
+| - | Subtraction operator |
+| * | Multiplication operator |
+| / | Division operator |
+| % | Remainder operator (Modulo) |
+| ^ | Power operator |
+
+h3. Boolean Operators
+|| Operator || Description ||
+| = | Equals |
+| == | Equals |
+| != | Not equals |
+| <> | Not equals |
+| < | Less than |
+| <= | Less than or equal to |
+| > | Greater than |
+| >= | Greater than or equal to |
+| && | Boolean and |
+| \|\| | Boolean or |
+
+h3. Supported Functions
+|| Function || Description ||
+| NOT(_expression_) | Boolean negation, 1 (means true) if the expression is not zero |
+| IF(_condition_,_value_if_true_,_value_if_false_) | Returns one value if the condition evaluates to true or the other if it evaluates to false |
+| RANDOM() | Produces a random number between 0 and 1 |
+| MIN(_e1_,_e2_) | Returns the smaller of both expressions |
+| MAX(_e1_,_e2_) | Returns the bigger of both expressions |
+| ABS(_expression_) | Returns the absolute (non-negative) value of the expression |
+| ROUND(_expression_,precision) | Rounds a value to a certain number of digits, uses the current rounding mode |
+| FLOOR(_expression_) | Rounds the value down to the nearest integer |
+| CEILING(_expression_) | Rounds the value up to the nearest integer |
+| LOG(_expression_) | Returns the natural logarithm (base e) of an expression |
+| SQRT(_expression_) | Returns the square root of an expression |
+| SIN(_expression_) | Returns the trigonometric sine of an angle (in degrees) |
+| COS(_expression_) | Returns the trigonometric cosine of an angle (in degrees) |
+| TAN(_expression_) | Returns the trigonometric tangens of an angle (in degrees) |
+| SINH(_expression_) | Returns the hyperbolic sine of a value |
+| COSH(_expression_) | Returns the hyperbolic cosine of a value |
+| TANH(_expression_) | Returns the hyperbolic tangens of a value |
+| RAD(_expression_) | Converts an angle measured in degrees to an approximately equivalent angle measured in radians |
+| DEG(_expression_) | Converts an angle measured in radians to an approximately equivalent angle measured in degrees |
+
+Functions names are case insensitive.
+
+h3. Supported Constants
+
+|| Constant || Description ||
+| PI | The value of _PI_, exact to 100 digits |
+| TRUE | The value one |
+| FALSE | The value zero |
+
h2. List, maps, pipes and closures
Using [], you can define array variable:
@@ -119,6 +192,8 @@ Apache Karaf console provides commands for scripting:
* {{shell:each}}
* ...
+See the [full list of {{shell}} commands|/commands/commands].
+
h2. Leveraging existing Java capabilities (via reflection)
Apache Karaf console supports loading and execution of Java classes.
http://git-wip-us.apache.org/repos/asf/karaf/blob/4aeed786/manual/src/main/webapp/users-guide/console.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/users-guide/console.conf b/manual/src/main/webapp/users-guide/console.conf
index 5191a5e..d386b78 100644
--- a/manual/src/main/webapp/users-guide/console.conf
+++ b/manual/src/main/webapp/users-guide/console.conf
@@ -315,6 +315,17 @@ karaf@root()> list = [1 2 3]; each ($list) { echo $it }
3
{code}
+{tip}
+The same loop could be written with the {{shell:while}} command:
+
+{code}
+karaf@root()> a = 0 ; while { %((a+=1) <= 3) } { echo $a }
+1
+2
+3
+{code}
+{tip}
+
You can create the list yourself (as in the previous example), or some commands can return a list too.
We can note that the console created a "session" variable with the name {{list}} that you can access with {{$list}}.