From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <5af454af871f92500ab67496a2152d52@vitanuova.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] Printenv(1) Date: Tue, 11 May 2004 19:41:57 +0100 From: rog@vitanuova.com In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: 7762a53c-eacd-11e9-9e20-41e7f4b1d025 > For something that handles lists properly, > > cd /env > whatis * | grep '=' pity about the "not found" messages, problems with variables containing newlines and other exceptions... for more-than-casual use, i think a C tool would probably be better, maybe something like this: #include #include void printenv(char *name, int len) { int r, f, z; char *ans, *t, *ep, *p; char *ename; ename = smprint("#e/%s", name); f = open(ename, OREAD); if(f < 0) return; ans = malloc(len+1); if(ans){ r = read(f, ans, len); print("%q=", name); if(r >= 0){ ep = ans + r; t = ans; z = 0; for(p = ans; p < ep; p++){ if(*p == '\0'){ print("%q ", t); t = p+1; z = 1; } } if(z == 0){ *p = '\0'; print("%q", ans); } print("\n"); } } close(f); free(ans); } void main(int, char **) { int fd, i; long nd; Dir *buf; fd = open("#e", OREAD); nd = dirreadall(fd, &buf); quotefmtinstall(); for(i = 0; i < nd; i++) printenv(buf[i].name, buf[i].length); }