昨日の を書いてる時に困ったとこ。コマンド慣れてないからかもしれないんだけど…。
簡単なの
Airof:GAdvent irof$ groovy -e "println 'hello'" hello PS> groovy -e "println 'hello'" hello
Macのほう
シングルクォテーションとダブルクォテーション逆にしたら駄目になる。
Airof:GAdvent irof$ groovy -e 'println "hello"'
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script_from_command_line: 1: unexpected char: 0xFFFF @ line 1, column 15.
println "hello
^
1 error最後スペースあけたらなんかいける。
Airof:GAdvent irof$ groovy -e 'println "hello" ' hello
なぜかこれが行ける。意味が分からない…。
Airof:GAdvent irof$ groovy -e 'println "hello"'" + 1" hello1
でもMacのほうはだいたいは何とかなる。
Windowsのほう
外側シングルクォテーションだと駄目なのは同じ。だけどエラー内容は違う。
PS> groovy -e 'println "hello"'
Caught: groovy.lang.MissingPropertyException: No such property: hello for class: script_from_command
_line
groovy.lang.MissingPropertyException: No such property: hello for class: script_from_command_line
at script_from_command_line.run(script_from_command_line:1)ちなみにWindowsはスペースあけてもだめ。PowerShellじゃなくcmdでやるとなんか待ち状態になる。Ctrl+Cで脱出。
cmdで最後スペース空けるとまた別のエラー。
C:\home\irof\work>groovy -e 'println "hello" '
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script_from_command_line: 1: expecting ''', found '<EOF>' @ line 1, column 9.
'println
^
1 error\"にすればとりあえずいける。
PS> groovy -e 'println \"hello\" ' hello
一応ちゃんとGString
PS> groovy -e 'println \"hello ${1*2*3}\" '
hello 6でも正直使い物にならない。
PS> groovy -e "println (1 % 2)"
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script_from_command_line: 1: unexpected token: 2 @ line 1, column 12.
println (1 2)
^
1 errorなんか % 使えないし。
もっときついのがクロージャ…
PS> groovy -e "println ((1..5).collect{ it * 2 })"
[2, 4, 6, 8, 10]it使うのならいけるんだけど…
PS> groovy -e "println ((1..5).collect{ i -> i * 2 })"
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script_from_command_line: 1: expecting '}', found '-' @ line 1, column 28.
println ((1..5).collect{ i - * 2 })
^
1 error引数とるとだめ。なぜか > がファイルに書き出すやつに勘違いしてるらしく、この場合 i ってファイルが作られてるのん…
PS> ls
ディレクトリ: C:\home\irof\work
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2011/12/22 0:27 0 iGroovyのせいじゃないだけに、もう、うん。
Windowsの人は素直にスクリプトファイルに書いて実行ですかね。cygwinなら大丈夫なんだろうけど。はぁ…。