Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top