How do I use conditional operator shell:if in karaf / jline
-
14-06-2021 - |
题
I am trying to conditionally execute a command using the apache karaf command line, which uses the jline library.
I can't find any documentation on the shell:if command.
For example in linux shell this works:
if [ "foo" = "foo" ]; then echo "good"; fi
When I change the syntax for karaf to:
if [ "foo" = "foo" ] echo "good"
I get the error:
Error executing command shell:if: unable to convert argument condition with value '{foo=foo}' to type org.apache.felix.service.command.Function
I've tried a bunch of different syntax, but I can't figure it out.
解决方案
Condition syntax works like this:
>if {true} {echo yes} {echo no}
yes
> if {false} {echo yes} {echo no}
no
This command uses closures for each part. This allows you to put an if inside of an each, for example.
其他提示
I've solved my string comparison problem like this:
if { $ENVIRONMENT equals "local" } {
echo "*** Altering configuration for local deployment using mocks ***"
} {
echo "*** Skipping ***"
}
Works like a charm, but I must agree the documentation is lacking in this area. (its 2014 now)
不隶属于 StackOverflow