#Something to do with environment variables

1 messages · Page 1 of 1 (latest)

robust tapir
#

Heyo, I'm having trouble getting Zig to pick up on certain environment variables, particularly ones that are set in the shell session rather than ?? however $USER et. al. are set:

# cat main.zig
const std = @import("std");

pub fn main() !void {
    std.log.info("pre-defined env vars work: {s}", .{ std.os.getenv("USER").? });
    std.log.info("explicitly set ones dont: {s}", .{ std.os.getenv("EDITOR").? });
}
# echo $USER
root
# echo $EDITOR
/usr/bin/vi
# ./main
info: pre-defined env vars work: root
thread 268 panic: attempt to use null value
/mnt/c/users/i/code/zk/mre/main.zig:5:77: 0x22cf88 in main (main)
    std.log.info("explicitly set ones dont: {s}", .{ std.os.getenv("EDITOR").? });

What's up with that? 😅 And is there something I can do about it?

fossil karma
#

is the variable exported in bash? if not, bash will not propagate it to subprocesses

export EDITOR
./main
robust tapir
#

ah 😓 that did it. thank you

#

I've never had that issue before. But I rarely touch environment variables I guess