From 1d5d64c1e8df14ca8821a4fb4870a590f144e3f0 Mon Sep 17 00:00:00 2001 From: syrmel <104119569+syrmel@users.noreply.github.com> Date: Sat, 27 Jan 2024 22:35:15 +0100 Subject: [PATCH] printenv - handle env variable being set to blank (#126) * Handle env variable being set to blank * v fmt printenv --- src/printenv/printenv.v | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/printenv/printenv.v b/src/printenv/printenv.v index 35981df7..db3370e0 100644 --- a/src/printenv/printenv.v +++ b/src/printenv/printenv.v @@ -40,8 +40,9 @@ fn main() { } } else { for k in args { - mut v := os.getenv(k) - if v == '' { + // Use getenv_opt because it is possible for the environment variable + // to be set to the empty string which should not return an error code. + mut v := os.getenv_opt(k) or { exit_code = 1 // at least one specified variable was not found continue }