The interactive shell uses a special shell interpretter and therefore has different behavior than just writting a script in Groovy. See the Groovy Shell Documentation for more on its usage. Notable differences:
Def statements do not define a variable in the context of the Shell, e.g. do not use def x = 1, use x = 1
Shell commands (as seen through help) using the non-functional shell syntax are only available in the shell.
Groovy classes using annotations cannot be parsed in the Shell.