From owner-svn-src-stable-9@FreeBSD.ORG Sat May 26 20:13:25 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 18889106564A; Sat, 26 May 2012 20:13:25 +0000 (UTC) (envelope-from mdf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 035A58FC0C; Sat, 26 May 2012 20:13:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q4QKDOgc004087; Sat, 26 May 2012 20:13:24 GMT (envelope-from mdf@svn.freebsd.org) Received: (from mdf@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q4QKDODI004084; Sat, 26 May 2012 20:13:24 GMT (envelope-from mdf@svn.freebsd.org) Message-Id: <201205262013.q4QKDODI004084@svn.freebsd.org> From: Matthew D Fleming Date: Sat, 26 May 2012 20:13:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r236118 - stable/9/bin/kenv X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 May 2012 20:13:25 -0000 Author: mdf Date: Sat May 26 20:13:24 2012 New Revision: 236118 URL: http://svn.freebsd.org/changeset/base/236118 Log: MFC r235297, r235316: Add a -v and -N option to kenv(1), so it can be more easily used in scripts the way sysctl(8) is. The -N option, like in sysctl(8), displays only the kenv names, not their values. The -v option prints an individual kenv variable name with its value as name="value". This is the inverse of sysctl(8)'s -n flag, since the default behaviour of kenv(1) is already like sysctl(8) -n. Modified: stable/9/bin/kenv/kenv.1 stable/9/bin/kenv/kenv.c Directory Properties: stable/9/bin/ (props changed) stable/9/bin/csh/ (props changed) stable/9/bin/df/ (props changed) stable/9/bin/ed/ (props changed) stable/9/bin/expr/ (props changed) stable/9/bin/ps/ (props changed) stable/9/bin/sh/ (props changed) Modified: stable/9/bin/kenv/kenv.1 ============================================================================== --- stable/9/bin/kenv/kenv.1 Sat May 26 20:03:47 2012 (r236117) +++ stable/9/bin/kenv/kenv.1 Sat May 26 20:13:24 2012 (r236118) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 13, 2009 +.Dd May 11, 2012 .Dt KENV 1 .Os .Sh NAME @@ -32,9 +32,9 @@ .Nd dump or modify the kernel environment .Sh SYNOPSIS .Nm -.Op Fl hq +.Op Fl hNq .Nm -.Op Fl q +.Op Fl qv .Ar variable Ns Op = Ns Ar value .Nm .Op Fl q @@ -54,6 +54,11 @@ name is specified, .Nm will only report that value. If the +.Fl N +option is specified, +.Nm +will only display variable names and not their values. +If the .Fl u option is specified, .Nm @@ -68,6 +73,13 @@ If the option is set, warnings normally printed as a result of being unable to perform the requested operation will be suppressed. .Pp +If the +.Fl v +option is set, the variable name will be printed out for the +environment variable in addition to the value when +.Nm +is executed with a variable name. +.Pp Variables can be added to the kernel environment using the .Pa /boot/loader.conf file, or also statically compiled into the kernel using the statement Modified: stable/9/bin/kenv/kenv.c ============================================================================== --- stable/9/bin/kenv/kenv.c Sat May 26 20:03:47 2012 (r236117) +++ stable/9/bin/kenv/kenv.c Sat May 26 20:13:24 2012 (r236118) @@ -42,15 +42,17 @@ static int ksetenv(char *, char *); static int kunsetenv(char *); static int hflag = 0; +static int Nflag = 0; static int qflag = 0; static int uflag = 0; +static int vflag = 0; static void usage(void) { (void)fprintf(stderr, "%s\n%s\n%s\n", - "usage: kenv [-hq]", - " kenv [-q] variable[=value]", + "usage: kenv [-hNq]", + " kenv [-qv] variable[=value]", " kenv [-q] -u variable"); exit(1); } @@ -64,17 +66,23 @@ main(int argc, char **argv) error = 0; val = NULL; env = NULL; - while ((ch = getopt(argc, argv, "hqu")) != -1) { + while ((ch = getopt(argc, argv, "hNquv")) != -1) { switch (ch) { case 'h': hflag++; break; + case 'N': + Nflag++; + break; case 'q': qflag++; break; case 'u': uflag++; break; + case 'v': + vflag++; + break; default: usage(); } @@ -91,9 +99,9 @@ main(int argc, char **argv) argv++; argc--; } - if (hflag && (env != NULL)) + if ((hflag || Nflag) && env != NULL) usage(); - if ((argc > 0) || (uflag && (env == NULL))) + if (argc > 0 || ((uflag || vflag) && env == NULL)) usage(); if (env == NULL) { error = kdumpenv(); @@ -152,7 +160,10 @@ kdumpenv(void) if (cp == NULL) continue; *cp++ = '\0'; - printf("%s=\"%s\"\n", buf, cp); + if (Nflag) + printf("%s\n", buf); + else + printf("%s=\"%s\"\n", buf, cp); buf = cp; } return (0); @@ -167,7 +178,10 @@ kgetenv(char *env) ret = kenv(KENV_GET, env, buf, sizeof(buf)); if (ret == -1) return (ret); - printf("%s\n", buf); + if (vflag) + printf("%s=\"%s\"\n", env, buf); + else + printf("%s\n", buf); return (0); }