2 * uname - print system information
4 * usage: uname [-amnrsv]
9 Copyright (C) 1999-2009 Free Software Foundation, Inc.
11 This file is part of GNU Bash.
12 Bash is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 Bash is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with Bash. If not, see <http://www.gnu.org/licenses/>.
29 #include "bashtypes.h"
31 #if defined (HAVE_UNAME)
32 # include <sys/utsname.h>
47 #include "bashgetopt.h"
50 #define FLAG_SYSNAME 0x01 /* -s */
51 #define FLAG_NODENAME 0x02 /* -n */
52 #define FLAG_RELEASE 0x04 /* -r */
53 #define FLAG_VERSION 0x08 /* -v */
54 #define FLAG_MACHINE 0x10 /* -m, -p */
64 static int uname_flags;
70 struct utsname uninfo;
73 reset_internal_getopt ();
74 while ((opt = internal_getopt (list, "amnprsv")) != -1)
79 uname_flags |= FLAG_ALL;
83 uname_flags |= FLAG_MACHINE;
86 uname_flags |= FLAG_NODENAME;
89 uname_flags |= FLAG_RELEASE;
92 uname_flags |= FLAG_SYSNAME;
95 uname_flags |= FLAG_VERSION;
110 if (uname_flags == 0)
111 uname_flags = FLAG_SYSNAME;
113 /* Only ancient systems will not have uname(2). */
115 if (uname (&uninfo) < 0)
117 builtin_error ("cannot get system name: %s", strerror (errno));
118 return (EXECUTION_FAILURE);
121 builtin_error ("cannot get system information: uname(2) not available");
122 return (EXECUTION_FAILURE);
125 uprint (FLAG_SYSNAME, uninfo.sysname);
126 uprint (FLAG_NODENAME, uninfo.nodename);
127 uprint (FLAG_RELEASE, uninfo.release);
128 uprint (FLAG_VERSION, uninfo.version);
129 uprint (FLAG_MACHINE, uninfo.machine);
131 return (EXECUTION_SUCCESS);
139 if (uname_flags & flag)
141 uname_flags &= ~flag;
142 printf ("%s%c", info, uname_flags ? ' ' : '\n');
146 char *uname_doc[] = {
147 "Display system information.",
149 "Display information about the system hardware and OS.",
153 struct builtin uname_struct = {