Why does this Java code print two arguments?

Viewed 158

The below Java code prints two arguments when I pass !clear as input as shown below.

class Test{

    public static void main(final String... arguments){
        for(String argument : arguments){
            System.out.println(argument);
        }
    }

}

Output:

$ java Test !clear
java Test clear
clear

UPDATE

Using any linux command in place of clear produces the same result.

$ java Test !pwd
java Test pwd
pwd

$ java Test !ls
java Test ls
ls

I am aware that this has got something to do with history expansion in bash and I can escape the ! character to solve this issue.

However, I am curious to know the exact reason why this code prints the above two lines as output. Could somebody please explain?

1 Answers
Related