Scala supports scripts
1) create a file hello. Scala under/opt/Scala-script and edit the file as follows:
$ Hello, this is the first Scala script
2) run the script
The command line parameters of the scala script are saved in the scala array named args. In Scala, the array uses0You can specify the index value in brackets to access array elements. The first element of the array ARGs in Scala is: ARGs (0), rather than: ARGs [0] Like java. Now, write the following content to the new file:
Test hellowithargs. scala:
// Send Hello println ("Hello:" + ARGs (0) to the first parameter ))
[Email protected]:/opt/Scala-script # Scala hello. Scala
Java.net. unknownhostexception: scala: Unknown error
At java.net. inetaddress. getlocalhost (inetaddress. Java: 1505)
At scala. Tools. nsc. Io. Socket $. localhost (socket. scala: 28)
At scala. Tools. nsc. compilesocket. getsock $1 (compilesocket. scala: 175)
At scala. Tools. nsc. compilesocket. getorcreatesocket (compilesocket. scala: 190)
At scala. Tools. nsc. scriptrunner. compilewithdaemon (scriptrunner. scala: 70)
At scala. tool. nsc. scriptrunner. Scala $ tools $ NSC $ scriptrunner $ compile $1 (scriptrunner. scala: 113)
At scala. Tools. nsc. scriptrunner $ anonfun $ withcompiledscript $1. Apply $ mcz $ Sp (scriptrunner. scala: 161)
At scala. Tools. nsc. scriptrunner $ anonfun $ withcompiledscript $1. Apply (scriptrunner. scala: 129)
At scala. Tools. nsc. scriptrunner $ anonfun $ withcompiledscript $1. Apply (scriptrunner. scala: 129)
At scala. Tools. nsc. util. Package $. trackingthreads (package. scala: 43)
At scala. Tools. nsc. util. Package $. waitingforthreads (package. scala: 27)
At scala. Tools. nsc. scriptrunner. withcompiledscript (scriptrunner. scala: 128)
At scala. Tools. nsc. scriptrunner. runscript (scriptrunner. scala: 192)
At scala. Tools. nsc. scriptrunner. runscriptandcatch (scriptrunner. scala: 205)
At scala. Tools. nsc. maingenericrunner. runtarget $1 (maingenericrunner. scala: 67)
At scala. Tools. nsc. maingenericrunner. run $1 (maingenericrunner. scala: 87)
At scala. Tools. nsc. maingenericrunner. Process (maingenericrunner. scala: 98)
At scala. Tools. nsc. maingenericrunner $. Main (maingenericrunner. scala: 103)
At scala. Tools. nsc. maingenericrunner. Main (maingenericrunner. Scala)
Caused by: java.net. unknownhostexception: scala: Unknown error
At java.net. inet6addressimpl. lookupallhostaddr (native method)
At java.net. inetaddress $2. lookupallhostaddr (inetaddress. Java: 928)
At java.net. inetaddress. getaddressesfromnameservice (inetaddress. Java: 1323)
At java.net. inetaddress. getlocalhost (inetaddress. Java: 1500)
... 18 more
[Original] Scala learning: compiling Scala scripts