Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Nim2
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Running Nim programs as scripts with shebang

Here I want to show you the nimbang project.

Installation:

$ nimble install nimbang

Then, you can write and execute Nim programs similarly to Python. Example:

#!/usr/bin/env nimbang

echo "hello nim"

Make it executable and launch it:

$ chmod u+x prg.nim

$ ./prg.nim
# nim c --colors:on --nimcache:/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E 
# --out:"/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E/.prg" "/tmp/send/prg.nim"
hello nim

$ ./prg.nim
hello nim

When you launch it for the first time, it's compiled, the EXE is cached in your HOME directory, and the EXE is executed. When you launch it for the second time, the cached EXE is found and just executed.

It's also intelligent. If you modify the source code, then the program will be re-compiled.

And the good news is that it's much faster than "nim r prg.nim":

$ time ./prg.nim
# nim c --colors:on --nimcache:/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E 
# --out:"/home/jabba/.cache/nimbang/nimcache-0E9E0F169BBD965E/.prg" "/tmp/send/prg.nim"
hello nim (252 msec)

$ time ./prg.nim
hello nim (4.59 msec)

By default, it makes a debug build. If you want to have a release build, add a special line under the shebang:

#!/usr/bin/env nimbang
#nimbang-args c -d:release

echo "hello nim"

For more info, see the README of the project: https://github.com/jabbalaci/nimbang

Template file

I suggest using the following template:

#!/usr/bin/env nimbang
#off:nimbang-args c -d:release

echo "hello nim"

Notice that the second line has "off:" in it, which makes the second line invalid for nimbang, thus the second line is just a normal comment. When you are ready with your program and you want to switch to release mode, then simply remove the substring "off:" from the second line.

Disclaimer

nimbang is my project. I found a project called nimcr and customized it to my needs. In the README I explain the key differences between nimbang and nimcr.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 March 19, 22:11