Skip to content

Instantly share code, notes, and snippets.

@Coutlaw
Created October 23, 2025 09:55
Show Gist options
  • Select an option

  • Save Coutlaw/4cd5f694fa8fdf784489115afdabe5ef to your computer and use it in GitHub Desktop.

Select an option

Save Coutlaw/4cd5f694fa8fdf784489115afdabe5ef to your computer and use it in GitHub Desktop.
First Zig program, executing bash from zig
const std = @import("std");
pub fn main() !void {
const allocator = std.heap.page_allocator;
const commands = &[_][]const u8{ "bash", "-c", "echo Hello from Bash" };
var child = std.process.Child.init(commands, allocator);
try child.spawn();
const term_sig = try child.wait();
switch (term_sig) {
.Exited => |code| {
if (code == 0) {
std.debug.print("Bash worked!\n", .{});
} else {
std.debug.print("Oopsie Whoopsie, we made a fucky wucky: {d}\n", .{code});
}
},
else => {
std.debug.print("Don't even know what sorts of fucked up we got to\n", .{});
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment