[Libguestfs] [PATCH 01/10] dib: fix listing envvars in fake-sudo

Pino Toscano ptoscano at redhat.com
Tue Feb 14 08:12:02 UTC 2017


Query awk for the list of environment variables, instead of trying to
extract the list from the output of `env`: the old approach breaks when
any of the environment variable contains more than one line.
---
 dib/dib.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dib/dib.ml b/dib/dib.ml
index 71b1f7f..54ea2ae 100644
--- a/dib/dib.ml
+++ b/dib/dib.ml
@@ -289,7 +289,7 @@ if [ -n \"$user\" ]; then
 fi
 
 if [ -z \"$preserve_env\" ]; then
-  for envvar in `env | grep '^\\w' | cut -d= -f1`; do
+  for envvar in `awk 'BEGIN{for (i in ENVIRON) {print i}}'`; do
     case \"$envvar\" in
       PATH | USER | USERNAME | HOSTNAME | TERM | LANG | HOME | SHELL | LOGNAME ) ;;
       BASH_FUNC_* ) unset -f $envvar ;;
-- 
2.9.3




More information about the Libguestfs mailing list