2 * uname - print system information
4 * usage: uname [-amnrsv]
11 #include "bashtypes.h"
13 #if defined (HAVE_UNAME)
14 # include <sys/utsname.h>
29 #include "bashgetopt.h"
31 #define FLAG_SYSNAME 0x01 /* -s */
32 #define FLAG_NODENAME 0x02 /* -n */
33 #define FLAG_RELEASE 0x04 /* -r */
34 #define FLAG_VERSION 0x08 /* -v */
35 #define FLAG_MACHINE 0x10 /* -m, -p */
45 static int uname_flags
;
51 struct utsname uninfo
;
54 reset_internal_getopt ();
55 while ((opt
= internal_getopt (list
, "amnprsv")) != -1)
60 uname_flags
|= FLAG_ALL
;
64 uname_flags
|= FLAG_MACHINE
;
67 uname_flags
|= FLAG_NODENAME
;
70 uname_flags
|= FLAG_RELEASE
;
73 uname_flags
|= FLAG_SYSNAME
;
76 uname_flags
|= FLAG_VERSION
;
92 uname_flags
= FLAG_SYSNAME
;
94 /* Only ancient systems will not have uname(2). */
96 if (uname (&uninfo
) < 0)
98 builtin_error ("cannot get system name: %s", strerror (errno
));
99 return (EXECUTION_FAILURE
);
102 builtin_error ("cannot get system information: uname(2) not available");
103 return (EXECUTION_FAILURE
);
106 uprint (FLAG_SYSNAME
, uninfo
.sysname
);
107 uprint (FLAG_NODENAME
, uninfo
.nodename
);
108 uprint (FLAG_RELEASE
, uninfo
.release
);
109 uprint (FLAG_VERSION
, uninfo
.version
);
110 uprint (FLAG_MACHINE
, uninfo
.machine
);
112 return (EXECUTION_SUCCESS
);
120 if (uname_flags
& flag
)
122 uname_flags
&= ~flag
;
123 printf ("%s%c", info
, uname_flags
? ' ' : '\n');
127 char *uname_doc
[] = {
128 "display information about the system",
132 struct builtin uname_struct
= {