package org.apache.felix.karaf.gshell.commands;

import java.util.List;

import org.apache.felix.gogo.commands.Command;
import org.apache.felix.gogo.commands.Option;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.karaf.gshell.console.OsgiCommandSupport;

@Command(scope = "shell", name = "echo", description="Echo or print arguments to STDOUT")
public class EchoAction extends OsgiCommandSupport
{
    @Option(name="-n", description="Do not print the trailing newline character")
    private boolean noTrailingNewline = false;

    @Argument(description="Arguments", multiValued = true)
    private List<String> args;

    protected Object doExecute() throws Exception {
        if (args != null) {
            int c=0;

            for (String arg : args) {
                System.out.print(arg);
                if (++c + 1 < args.size()) {
                    System.out.print(" ");
                }
            }
        }

        if (!noTrailingNewline) {
            System.out.println();
        }

        return null;
    }
}
@@ -733,17 +733,29 @@
     
-int c=0;%0A
+boolean first = true;
 %0A   
@@ -809,73 +809,78 @@
     
-System.out.print(arg);%0A                if (++c + 1 %3C args.size())
+if (first) %7B%0A                    first = false;%0A                %7D else
  %7B%0A 
@@ -931,32 +931,71 @@
               %7D%0A
+                System.out.print(arg);%0A
             %7D%0A  

Fix karaf echo command