Scala Script Issue

Banashri
Windoof-User
Windoof-User
Beiträge: 25
Registriert: 19. Dez 2013 02:55

Scala Script Issue

Beitrag von Banashri »

Hello All,
I need a small help regarding an issue while executing a Scala script.

I am trying to run a scala script (named Hey.scala) which contains only the code: args.foreach(println)
From the console I run this command:
scala Hey.scala Scala is really fun!!!!!

The output:
Scala
is
really
fun

Could you please tell me why exclamation marks got disappeared?

Thanks!

ManuelWeiel
Mausschubser
Mausschubser
Beiträge: 72
Registriert: 7. Okt 2014 11:38

Re: Scala Script Issue

Beitrag von ManuelWeiel »

Hi,

your problem is not scala related. You run the scala interpreter and pass additional arguments. Now bash (or whatever terminal you are using) is interpreting every word as a separate argument. The ! is a reserved keyword though... This is why it will not be printed. In bash it will even throw an error message...

What you can do is surround your arguments in single quotes ('). Then you will get the expected result:

Code: Alles auswählen

scala Hey.scala Hey 'Scala is really fun!!!'
Also make sure to pass the name of the object that contains the main method as the second parameter after the name (I assume it is called Hey here).

Best,
Manuel

Antworten

Zurück zu „Archiv“