Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement echo #11

Open
kjloveless opened this issue Apr 22, 2024 · 1 comment
Open

Implement echo #11

kjloveless opened this issue Apr 22, 2024 · 1 comment

Comments

@kjloveless
Copy link
Owner

Mistakenly thought echo was a native program we could rely on...

Noticed that it functions like this currently:

echo $PATH
$PATH

Found this stackoverflow post when looking into this problem

Furthermore I found this function in Zig std

Looking at some other shells (bash & fish) we may want to expand environment variables before executing the utility.

@kjloveless
Copy link
Owner Author

kjloveless commented Apr 22, 2024

const std = @import("std");

pub fn main() !void {
  var gpa = std.heap.GeneralPurposeAllocator(.{}){};
  const allocator = gpa.allocator();
  const env = try std.process.getEnvMap(allocator);

  var it = env.hash_map.iterator();
  while (it.next()) |entry| {
    const key = entry.key_ptr.*;
    const value = entry.value_ptr.*;
    std.debug.print("{s}: {s}\n", .{key, value});
  }
  std.debug.print("{s}", .{env.get("NAME").?});
}

Was messing around and came with the preceding snippet, should be useful in argument expansion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant