Nuss9940/zigscript
Run a zig file directly by using a shebang line
Put the zigscript file in this repository on your $PATH
# ln -s zigscript /usr/local/bin/
Simply put
#!/usr/bin/env zigscript
in the first line of your script.
Example:
#!/usr/bin/env zigscript
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {}!\n", .{"world"});
}
Save it as example
, make sure it's executable and run it:
$ ./example
Hello, world!
It simply copies your script to another directory excluding the first line. Then zig run
is
called with the copied file as an argument. It compiles the code and runs the result. Zig's caching
system will make sure to only recompile when there are changes in the script.
Closed issue on this topic: https://github.com/ziglang/zig/issues/2165