Closed vitaliel closed 2 years ago
I found similar tool that works in nim 1.6.2 https://github.com/lee-b/nimrun
You seem to have trouble naming your file correctly. If you name it script_sample.nim
you should be able to have
#!/usr/bin/env nimcr
echo "Hello"
in that file and then run it with: ./script_sample.nim
.
The first error you showed is just a Nim error because you can't have dashes in the module/filename.
EDIT: Also note that nimrun
and nimcr
differs quite significantly in how they work. nimcr
essentially calls nim c -r
on your file, it allows extra arguments both to the compiler and your program, and caches the resulting build so subsequent runs are as quick as the compiled binary. nimrun
creates a nimble package behind the scenes, this has the side effect that you can't run external packages from your script. And it doesn't cache the result, meaning it will rebuild your script every time you run it.
Hi, I tried
nimcr
, but I got errors. I can use.nims
extension for scripting, but wanted a script without it.Script file script-sample:
I renamed file to
script_sample